Enable MXC selection through Windows sandbox configuration (#46271)

## What changed

- Accept `windows.sandbox = "mxc"` and preserve the selected backend through environment configuration, command execution, patch writes, and sandbox metadata.
- Treat MXC as enabled in the TUI and report Windows sandbox readiness as `ready`, avoiding legacy setup prompts.
- Keep `allowed_sandbox_implementations` scoped to the legacy elevated and unelevated backends without restricting MXC.
- Default `windows.sandbox_private_desktop` to `false` for MXC while retaining `true` for legacy sandboxes.

## Testing

Add coverage for MXC configuration precedence, legacy requirement handling, sandbox selection, and TUI state. Add a Wine integration test that verifies command and patch routing fails when native MXC is unavailable and reports `windows_mxc` in turn metadata.

GitOrigin-RevId: e2162447d0750f60753864c92a20e02a7f297bca
This commit is contained in:
iceweasel-oai authored and copyberry committed 2026-09-17 18:20:28 +00:00
1 parent 3d3ae4965a
commit 8b78600dc8
72 files changed
+557 -142

No files matched your search

@@ -37,6 +37,7 @@ use crate::tools::registry::ToolExecutor;
use crate::tools::runtimes::apply_patch::ApplyPatchRequest;
use crate::tools::runtimes::apply_patch::ApplyPatchRuntime;
use crate::tools::sandboxing::ToolCtx;
use crate::windows_sandbox::windows_sandbox_level_for_legacy_checks;
use codex_apply_patch::ApplyPatchAction;
use codex_apply_patch::ApplyPatchFileChange;
use codex_apply_patch::ApplyPatchFileUpdateMode;
@@ -556,7 +557,10 @@ async fn execute_verified_patch(
let sandbox_route = if turn_environment.environment.is_remote() {
PatchSandboxRoute::ExecutorManaged
} else {
PatchSandboxRoute::Platform(turn_environment.config().windows_sandbox_level)
PatchSandboxRoute::Platform(windows_sandbox_level_for_legacy_checks(
turn_environment.config().windows_sandbox_type,
turn_environment.config().windows_sandbox_level,
))
};
let (file_paths, effective_additional_permissions, file_system_sandbox_policy) =
effective_patch_permissions(
@@ -212,7 +212,10 @@ impl ExecCommandHandler {
&& SandboxManager::new().select_initial(
turn_environment.permission_profile(),
SandboxablePreference::Auto,
turn_environment.config().windows_sandbox_level,
codex_protocol::sandbox::effective_windows_sandbox_type(
turn_environment.config().windows_sandbox_type,
turn_environment.config().windows_sandbox_level,
),
turn.network.is_some(),
) != SandboxType::None;
// `to_abs_path()` alone cannot identify foreign drive paths: `file:///C:/repo` is
+9 -2
View File
@@ -90,6 +90,7 @@ impl ToolOrchestrator {
workspace_roots: attempt.workspace_roots,
sandbox_exe: attempt.sandbox_exe,
use_legacy_landlock: attempt.use_legacy_landlock,
windows_sandbox_type: attempt.windows_sandbox_type,
windows_sandbox_level: attempt.windows_sandbox_level,
windows_sandbox_private_desktop: attempt.windows_sandbox_private_desktop,
network_denial_cancellation_token: network_approval
@@ -275,11 +276,15 @@ impl ToolOrchestrator {
managed_network_active,
),
};
let windows_sandbox_type = codex_protocol::sandbox::effective_windows_sandbox_type(
sandbox_config.windows_sandbox_type,
sandbox_config.windows_sandbox_level,
);
let initial_sandbox = if sandbox_requested && !executor_managed_process_sandbox {
sandbox_manager.select_initial(
&permissions,
sandbox_preference,
sandbox_config.windows_sandbox_level,
windows_sandbox_type,
managed_network_active,
)
} else {
@@ -306,6 +311,7 @@ impl ToolOrchestrator {
workspace_roots,
sandbox_exe: codex_sandbox_exe,
use_legacy_landlock: sandbox_config.use_legacy_landlock,
windows_sandbox_type,
windows_sandbox_level: sandbox_config.windows_sandbox_level,
windows_sandbox_private_desktop: sandbox_config.windows_sandbox_private_desktop,
network_denial_cancellation_token: None,
@@ -458,7 +464,7 @@ impl ToolOrchestrator {
sandbox_manager.select_initial(
&permissions,
sandbox_preference,
sandbox_config.windows_sandbox_level,
windows_sandbox_type,
managed_network_active,
)
} else {
@@ -480,6 +486,7 @@ impl ToolOrchestrator {
workspace_roots,
sandbox_exe: retry_sandbox_exe,
use_legacy_landlock: sandbox_config.use_legacy_landlock,
windows_sandbox_type,
windows_sandbox_level: sandbox_config.windows_sandbox_level,
windows_sandbox_private_desktop: sandbox_config.windows_sandbox_private_desktop,
network_denial_cancellation_token: None,
@@ -103,6 +103,7 @@ impl ApplyPatchRuntime {
user_home_dir: req.turn_environment.user_home_dir.clone(),
temporary_directories: None,
windows_sandbox_selection: executor_windows_sandbox_selection(
attempt.windows_sandbox_type,
attempt.windows_sandbox_level,
attempt.sandbox_cwd,
),
@@ -29,6 +29,7 @@ fn test_turn_environment(environment_id: &str) -> crate::session::turn_context::
allow_login_shell: true,
workspace_roots: Vec::new(),
windows_sandbox_level: WindowsSandboxLevel::Disabled,
windows_sandbox_type: SandboxType::None,
windows_sandbox_private_desktop: true,
use_legacy_landlock: false,
permission_profile: PermissionProfileSnapshot::legacy(
@@ -248,6 +249,7 @@ async fn file_system_sandbox_context_preserves_executor_workspace_permissions()
workspace_roots: std::slice::from_ref(&sandbox_policy_cwd),
sandbox_exe: None,
use_legacy_landlock: true,
windows_sandbox_type: SandboxType::WindowsRestrictedToken,
windows_sandbox_level: WindowsSandboxLevel::RestrictedToken,
windows_sandbox_private_desktop: true,
network_denial_cancellation_token: None,
@@ -316,6 +318,7 @@ async fn file_system_sandbox_context_respects_sandbox_request() {
workspace_roots: std::slice::from_ref(&sandbox_policy_cwd),
sandbox_exe: None,
use_legacy_landlock: false,
windows_sandbox_type: SandboxType::None,
windows_sandbox_level: WindowsSandboxLevel::Disabled,
windows_sandbox_private_desktop: false,
network_denial_cancellation_token: None,
@@ -126,6 +126,7 @@ async fn explicit_escalation_prepares_exec_without_managed_network() -> anyhow::
workspace_roots: std::slice::from_ref(&sandbox_policy_cwd),
sandbox_exe: None,
use_legacy_landlock: false,
windows_sandbox_type: SandboxType::None,
windows_sandbox_level: WindowsSandboxLevel::Disabled,
windows_sandbox_private_desktop: false,
network_denial_cancellation_token: None,
@@ -752,6 +752,7 @@ mod tests {
allow_login_shell: true,
workspace_roots: Vec::new(),
windows_sandbox_level: WindowsSandboxLevel::Disabled,
windows_sandbox_type: codex_sandboxing::SandboxType::None,
windows_sandbox_private_desktop: true,
use_legacy_landlock: false,
permission_profile: PermissionProfileSnapshot::legacy(
@@ -768,7 +768,7 @@ impl CoreShellCommandExecutor {
let sandbox = sandbox_manager.select_initial(
permission_profile,
SandboxablePreference::Auto,
self.windows_sandbox_level,
SandboxType::None,
self.network.is_some(),
);
let cwd = PathUri::from_abs_path(workdir);
+25 -4
View File
@@ -399,6 +399,7 @@ pub(crate) struct SandboxAttempt<'a> {
// TODO(anp): Reconcile these attempt settings with TurnEnvironment::sandbox_context
// so process execution and patch writes honor the selected environment's backend.
pub use_legacy_landlock: bool,
pub windows_sandbox_type: SandboxType,
pub windows_sandbox_level: codex_protocol::config_types::WindowsSandboxLevel,
pub windows_sandbox_private_desktop: bool,
pub network_denial_cancellation_token: Option<CancellationToken>,
@@ -406,10 +407,12 @@ pub(crate) struct SandboxAttempt<'a> {
}
pub(crate) fn executor_windows_sandbox_level(
windows_sandbox_type: SandboxType,
windows_sandbox_level: WindowsSandboxLevel,
cwd: &PathUri,
) -> WindowsSandboxLevel {
if windows_sandbox_level == WindowsSandboxLevel::Disabled
if windows_sandbox_type != SandboxType::WindowsMxc
&& windows_sandbox_level == WindowsSandboxLevel::Disabled
&& cwd.infer_path_convention() == Some(PathConvention::Windows)
{
WindowsSandboxLevel::RestrictedToken
@@ -419,13 +422,30 @@ pub(crate) fn executor_windows_sandbox_level(
}
pub(crate) fn executor_windows_sandbox_selection(
windows_sandbox_type: SandboxType,
windows_sandbox_level: WindowsSandboxLevel,
cwd: &PathUri,
) -> WindowsSandboxSelection {
if cwd.infer_path_convention() == Some(PathConvention::Windows) {
executor_windows_sandbox_level(windows_sandbox_level, cwd).into()
configured_windows_sandbox_selection(
windows_sandbox_type,
executor_windows_sandbox_level(windows_sandbox_type, windows_sandbox_level, cwd),
cwd,
)
}
pub(crate) fn configured_windows_sandbox_selection(
windows_sandbox_type: SandboxType,
windows_sandbox_level: WindowsSandboxLevel,
cwd: &PathUri,
) -> WindowsSandboxSelection {
if cwd.infer_path_convention() != Some(PathConvention::Windows) {
return WindowsSandboxSelection::Disabled;
}
if windows_sandbox_type == SandboxType::WindowsMxc {
WindowsSandboxSelection::Mxc
} else {
WindowsSandboxSelection::Disabled
windows_sandbox_level.into()
}
}
@@ -526,6 +546,7 @@ impl<'a> SandboxAttempt<'a> {
user_home_dir: None,
temporary_directories: None,
windows_sandbox_selection: executor_windows_sandbox_selection(
self.windows_sandbox_type,
self.windows_sandbox_level,
self.sandbox_cwd,
),
@@ -73,6 +73,43 @@ fn restricted_sandbox_requires_exec_approval_on_request() {
);
}
#[test]
fn windows_sandbox_selection_distinguishes_configured_and_executor_defaults() {
let cwd = PathUri::parse("file:///C:/workspace").expect("Windows path URI");
assert_eq!(
executor_windows_sandbox_level(
SandboxType::WindowsMxc,
codex_protocol::config_types::WindowsSandboxLevel::Disabled,
&cwd,
),
codex_protocol::config_types::WindowsSandboxLevel::Disabled,
);
assert_eq!(
executor_windows_sandbox_selection(
SandboxType::WindowsMxc,
codex_protocol::config_types::WindowsSandboxLevel::Disabled,
&cwd,
),
codex_file_system::WindowsSandboxSelection::Mxc,
);
assert_eq!(
configured_windows_sandbox_selection(
SandboxType::None,
codex_protocol::config_types::WindowsSandboxLevel::Disabled,
&cwd,
),
codex_file_system::WindowsSandboxSelection::Disabled,
);
assert_eq!(
executor_windows_sandbox_selection(
SandboxType::None,
codex_protocol::config_types::WindowsSandboxLevel::Disabled,
&cwd,
),
codex_file_system::WindowsSandboxSelection::RestrictedToken,
);
}
#[test]
fn default_exec_approval_requirement_rejects_sandbox_prompt_when_granular_disables_it() {
let policy = AskForApproval::Granular(GranularApprovalConfig {
@@ -257,6 +294,7 @@ fn windows_sandbox_env_preserves_denied_reads_or_rejects_unsupported_backend() {
workspace_roots: std::slice::from_ref(&cwd_uri),
sandbox_exe: None,
use_legacy_landlock: false,
windows_sandbox_type: SandboxType::WindowsRestrictedToken,
windows_sandbox_level: codex_protocol::config_types::WindowsSandboxLevel::Elevated,
windows_sandbox_private_desktop: false,
network_denial_cancellation_token: None,
@@ -328,6 +366,7 @@ fn exec_server_env_keeps_command_native_and_carries_sandbox_context() {
workspace_roots: std::slice::from_ref(&cwd_uri),
sandbox_exe: None,
use_legacy_landlock: false,
windows_sandbox_type: SandboxType::None,
windows_sandbox_level: codex_protocol::config_types::WindowsSandboxLevel::Disabled,
windows_sandbox_private_desktop: false,
network_denial_cancellation_token: None,
@@ -1256,6 +1256,7 @@ async fn zsh_fork_unified_exec_keeps_shell_parameter_when_remote_environment_ava
allow_login_shell: true,
workspace_roots: Vec::new(),
windows_sandbox_level: turn.windows_sandbox_level,
windows_sandbox_type: turn.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: turn
.config
.permissions