Separate executor sandbox selection from Windows sandbox levels (#45730)

## Why

MXC is a sandbox implementation, not a restricted-token sandbox level. Executor requests need to represent that choice separately from `WindowsSandboxLevel`.

## What changed

- Introduce `WindowsSandboxSelection` for executor sandbox contexts and remove `Mxc` from `WindowsSandboxLevel`.
- Preserve the `windowsSandboxLevel` wire field and its serialized values for compatibility.
- Share sandbox selection between executor process launches and filesystem helpers, and use the new selection in capability discovery and skill reads.
- Disable Windows sandbox selection for executor paths that do not use Windows path conventions.

## Testing

Extend coverage for MXC wire serialization, Windows skill-read sandbox checks, and capability discovery with distinct permissions. Exercise remote filesystem write restrictions with both restricted-token and MXC sandboxes, including rejection when native MXC is unavailable.

GitOrigin-RevId: 266211377bcb138a0dc75861e9ff2225fa37a53d
This commit is contained in:
iceweasel-oai authored and copyberry committed 2026-09-15 16:40:06 +00:00
1 parent a9d2564bcb
commit d4e11a9b97
32 files changed
+256 -150

No files matched your search

@@ -25,7 +25,7 @@ pub fn prepare_windows_sandbox_config(
let selected_mode = configured_mode.or(match feature_level {
WindowsSandboxLevel::Elevated => Some(WindowsSandboxModeToml::Elevated),
WindowsSandboxLevel::RestrictedToken => Some(WindowsSandboxModeToml::Unelevated),
WindowsSandboxLevel::Disabled | WindowsSandboxLevel::Mxc => None,
WindowsSandboxLevel::Disabled => None,
});
apply_requirement_constrained_value("windows.sandbox", selected_mode, constraint, warnings)?;
let effective_mode = *constraint.get();
-1
View File
@@ -79,7 +79,6 @@ fn permission_profile_sandbox_tag(
}
if cfg!(target_os = "windows") {
match windows_sandbox_level {
WindowsSandboxLevel::Mxc => return "windows_mxc",
WindowsSandboxLevel::Elevated => return "windows_elevated",
WindowsSandboxLevel::Disabled | WindowsSandboxLevel::RestrictedToken => {}
}
+5 -1
View File
@@ -8970,7 +8970,11 @@ async fn capability_discovery_uses_environment_permission_profile() {
workspace_roots: environment.workspace_roots().to_vec(),
user_home_dir: environment.user_home_dir.clone(),
temporary_directories: environment.temporary_directories.clone(),
windows_sandbox_level: WindowsSandboxLevel::Elevated,
windows_sandbox_selection: if cfg!(windows) {
codex_file_system::WindowsSandboxSelection::Elevated
} else {
codex_file_system::WindowsSandboxSelection::Disabled
},
windows_sandbox_private_desktop: false,
windows_sandbox_proxy_settings_mode: None,
use_legacy_landlock: true,
+2 -2
View File
@@ -9,7 +9,7 @@ use crate::exec_policy::AllowPrefixRules;
use crate::shell_snapshot::ShellSnapshot;
use crate::shell_snapshot::ShellSnapshotFile;
use crate::shell_snapshot::ShellSnapshotSandbox;
use crate::tools::sandboxing::executor_windows_sandbox_level;
use crate::tools::sandboxing::executor_windows_sandbox_selection;
use arc_swap::ArcSwap;
use codex_core_plugins::PluginCommandAttribution;
use codex_core_plugins::ResolvedPluginMetricsOperation;
@@ -227,7 +227,7 @@ impl TurnEnvironment {
workspace_roots: self.workspace_roots().to_vec(),
user_home_dir: self.user_home_dir.clone(),
temporary_directories: self.temporary_directories.clone(),
windows_sandbox_level: executor_windows_sandbox_level(
windows_sandbox_selection: executor_windows_sandbox_selection(
config.windows_sandbox_level,
self.cwd(),
),
@@ -13,7 +13,7 @@ use crate::tools::sandboxing::Sandboxable;
use crate::tools::sandboxing::ToolCtx;
use crate::tools::sandboxing::ToolError;
use crate::tools::sandboxing::ToolRuntime;
use crate::tools::sandboxing::executor_windows_sandbox_level;
use crate::tools::sandboxing::executor_windows_sandbox_selection;
use codex_apply_patch::AppliedPatchDelta;
use codex_apply_patch::ApplyPatchAction;
use codex_apply_patch::ApplyPatchOptions;
@@ -102,7 +102,7 @@ impl ApplyPatchRuntime {
workspace_roots: attempt.workspace_roots.to_vec(),
user_home_dir: req.turn_environment.user_home_dir.clone(),
temporary_directories: None,
windows_sandbox_level: executor_windows_sandbox_level(
windows_sandbox_selection: executor_windows_sandbox_selection(
attempt.windows_sandbox_level,
attempt.sandbox_cwd,
),
@@ -276,8 +276,12 @@ async fn file_system_sandbox_context_preserves_executor_workspace_permissions()
Some(codex_utils_path_uri::PathUri::from_abs_path(&path))
);
assert_eq!(
sandbox.windows_sandbox_level,
WindowsSandboxLevel::RestrictedToken
sandbox.windows_sandbox_selection,
if cfg!(windows) {
codex_file_system::WindowsSandboxSelection::RestrictedToken
} else {
codex_file_system::WindowsSandboxSelection::Disabled
}
);
assert_eq!(sandbox.windows_sandbox_private_desktop, true);
assert_eq!(sandbox.use_legacy_landlock, true);
@@ -349,7 +353,7 @@ async fn file_system_sandbox_context_respects_sandbox_request() {
workspace_roots: vec![cwd],
user_home_dir: Some(user_home_dir),
temporary_directories: None,
windows_sandbox_level: WindowsSandboxLevel::RestrictedToken,
windows_sandbox_selection: codex_file_system::WindowsSandboxSelection::RestrictedToken,
windows_sandbox_private_desktop: false,
windows_sandbox_proxy_settings_mode: None,
use_legacy_landlock: false,
+13 -1
View File
@@ -13,6 +13,7 @@ use crate::state::SessionServices;
use crate::tools::hook_names::HookToolName;
use crate::tools::network_approval::NetworkApprovalSpec;
use codex_file_system::FileSystemSandboxContext;
use codex_file_system::WindowsSandboxSelection;
use codex_network_proxy::NetworkProxy;
use codex_protocol::approvals::ExecPolicyAmendment;
use codex_protocol::config_types::WindowsSandboxLevel;
@@ -417,6 +418,17 @@ pub(crate) fn executor_windows_sandbox_level(
}
}
pub(crate) fn executor_windows_sandbox_selection(
windows_sandbox_level: WindowsSandboxLevel,
cwd: &PathUri,
) -> WindowsSandboxSelection {
if cwd.infer_path_convention() == Some(PathConvention::Windows) {
executor_windows_sandbox_level(windows_sandbox_level, cwd).into()
} else {
WindowsSandboxSelection::Disabled
}
}
impl<'a> SandboxAttempt<'a> {
/// Whether this attempt bypasses sandboxing required by its ambient policy.
/// Use the requested policy, not the controller's wrapper, for remote executors.
@@ -513,7 +525,7 @@ impl<'a> SandboxAttempt<'a> {
workspace_roots: self.workspace_roots.to_vec(),
user_home_dir: None,
temporary_directories: None,
windows_sandbox_level: executor_windows_sandbox_level(
windows_sandbox_selection: executor_windows_sandbox_selection(
self.windows_sandbox_level,
self.sandbox_cwd,
),
+3 -3
View File
@@ -373,10 +373,10 @@ fn exec_server_env_keeps_command_native_and_carries_sandbox_context() {
workspace_roots: vec![cwd_uri.clone()],
user_home_dir: None,
temporary_directories: None,
windows_sandbox_level: if cfg!(windows) {
codex_protocol::config_types::WindowsSandboxLevel::RestrictedToken
windows_sandbox_selection: if cfg!(windows) {
codex_file_system::WindowsSandboxSelection::RestrictedToken
} else {
codex_protocol::config_types::WindowsSandboxLevel::Disabled
codex_file_system::WindowsSandboxSelection::Disabled
},
windows_sandbox_private_desktop: false,
windows_sandbox_proxy_settings_mode: None,
@@ -27,7 +27,7 @@ use crate::exec_env::inject_session_env;
use crate::session::session::Session;
use crate::session::step_context::StepContext;
use crate::shell::ShellType;
use crate::tools::sandboxing::executor_windows_sandbox_level;
use crate::tools::sandboxing::executor_windows_sandbox_selection;
impl Session {
pub(crate) fn prewarm_shell_snapshots(
@@ -97,7 +97,7 @@ impl Session {
workspace_roots: environment.workspace_roots().to_vec(),
user_home_dir: None,
temporary_directories: None,
windows_sandbox_level: executor_windows_sandbox_level(
windows_sandbox_selection: executor_windows_sandbox_selection(
environment.config().windows_sandbox_level,
environment.cwd(),
),
@@ -1,7 +1,7 @@
//! Reviews terminal input against retained launch permissions and current policy.
//! Permission snapshots stay host-owned; neither an earlier approval nor a policy
//! change alters the sandbox of an already-running process. Native launches keep
//! their configured Windows sandbox level; executor launches use executor defaults.
//! their configured Windows sandbox selection; executor launches use executor defaults.
use super::ProcessEntry;
use super::UnifiedExecContext;
@@ -56,7 +56,7 @@ impl TerminalPolicy {
if matches!(sandbox_source, TerminalSandboxSource::Native) {
// The filesystem helper applies executor defaults, but native process
// launches honor Disabled. Preserve it so later enablement is detected.
sandbox.windows_sandbox_level = environment.config().windows_sandbox_level;
sandbox.windows_sandbox_selection = environment.config().windows_sandbox_level.into();
}
Self {
sandbox,