Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add global setting to enable or disable the agent sandbox (#59497)

Richard Feldmandd7e50e66bb0
diff --git a/crates/settings_ui/src/pages/sandbox_settings.rs b/crates/settings_ui/src/pages/sandbox_settings.rs
index b1d1c46ac80..02ef0183a62 100644
--- a/crates/settings_ui/src/pages/sandbox_settings.rs
+++ b/crates/settings_ui/src/pages/sandbox_settings.rs
@@ -50,6 +50,7 @@ pub(crate) fn render_sandbox_settings_page(
let add_path_input = render_add_path_input(cx);
let empty_border = cx.theme().colors().border_variant;
+ let sandbox_enabled = !permissions.disabled;
v_flex()
.id("sandbox-settings-page")
@@ -68,6 +69,22 @@ pub(crate) fn render_sandbox_settings_page(
.mt_0p5(),
),
)
+ .child(
+ SwitchField::new(
+ "sandbox-enabled",
+ Some("Enable Sandbox"),
+ Some(
+ "Wrap agent-run terminal commands in an OS-level sandbox. When off, commands run with Zed's own permissions."
+ .into(),
+ ),
+ sandbox_enabled,
+ move |state, _window, cx| {
+ set_sandbox_enabled(*state == ToggleState::Selected, cx);
+ },
+ )
+ .tab_index(0),
+ )
+ .when(sandbox_enabled, |this| this
.when_some(validation_error, |this, error| {
this.child(
Banner::new()
@@ -158,7 +175,7 @@ pub(crate) fn render_sandbox_settings_page(
)
.tab_index(0),
),
- )
+ ))
.into_any_element()
}
@@ -411,6 +428,14 @@ fn update_sandbox_permissions(
});
}
+fn set_sandbox_enabled(value: bool, cx: &mut App) {
+ // The UI presents an "enabled" switch, but the stored setting is the
+ // inverse (`disabled`).
+ update_sandbox_permissions(cx, move |permissions| {
+ permissions.disabled = Some(!value);
+ });
+}
+
fn set_allow_all_hosts(value: bool, cx: &mut App) {
update_sandbox_permissions(cx, move |permissions| {
permissions.allow_all_hosts = Some(value);