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

@@ -385,6 +385,7 @@ async fn v2_residency_reload_preserves_inherited_environment_and_tools(
permission_profile: PermissionProfileSnapshot::legacy(child_permissions),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
@@ -52,11 +52,13 @@ use codex_utils_path_uri::PathUri;
use core_test_support::PathBufExt;
use core_test_support::TestTargetOs;
use core_test_support::assert_regex_match;
use core_test_support::is_wine_exec_test_environment;
use core_test_support::responses::ev_assistant_message;
use core_test_support::responses::ev_completed;
use core_test_support::responses::ev_exec_command_call_with_args;
use core_test_support::responses::ev_function_call;
use core_test_support::responses::ev_response_created;
use core_test_support::responses::mount_function_call_agent_response;
use core_test_support::responses::mount_sse_sequence;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
@@ -244,6 +246,68 @@ pub async fn mount_apply_patch(
.await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn mxc_config_routes_command_and_patch_to_the_windows_executor() -> Result<()> {
if !is_wine_exec_test_environment() {
return Ok(());
}
let harness = apply_patch_harness_with(|builder| {
builder.with_pre_build_hook(|home| {
fs::write(home.join("config.toml"), "[windows]\nsandbox = \"mxc\"\n")
.expect("write MXC config");
})
})
.await?;
let exec_response = mount_function_call_agent_response(
harness.server(),
"mxc-exec",
&json!({"cmd": "Write-Output should-not-run"}).to_string(),
"exec_command",
)
.await;
harness
.submit_with_permission_profile(
"exercise MXC command routing",
PermissionProfile::workspace_write(),
)
.await?;
mount_apply_patch(
&harness,
"mxc-patch",
"*** Begin Patch\n*** Add File: should-not-exist.txt\n+blocked\n*** End Patch",
"done",
)
.await;
harness
.submit_with_permission_profile(
"exercise MXC patch routing",
PermissionProfile::workspace_write(),
)
.await?;
let exec_output = harness.function_call_stdout("mxc-exec").await;
assert!(
exec_output.contains("native MXC is unavailable"),
"expected MXC unavailability error, got: {exec_output:?}"
);
let patch_output = harness.apply_patch_output("mxc-patch").await;
assert!(
patch_output.contains("Failed to write file"),
"expected apply_patch failure, got: {patch_output:?}"
);
let metadata: serde_json::Value = serde_json::from_str(
&exec_response
.function_call
.single_request()
.header("x-codex-turn-metadata")
.expect("turn metadata header"),
)?;
assert_eq!(metadata["sandbox"], "windows_mxc");
Ok(())
}
async fn mount_apply_patch_model_output(
harness: &TestCodexHarness,
call_id: &str,
+3
View File
@@ -720,6 +720,7 @@ async fn environment_command_restrictions_override_saved_prefix_approvals() -> R
permission_profile: PermissionProfileSnapshot::legacy(PermissionProfile::Disabled),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
@@ -750,6 +751,7 @@ async fn environment_command_restrictions_override_saved_prefix_approvals() -> R
permission_profile: PermissionProfileSnapshot::legacy(PermissionProfile::Disabled),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
@@ -861,6 +863,7 @@ async fn environment_command_policy_changes_invalidate_session_approvals() -> Re
),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
@@ -1633,6 +1633,7 @@ async fn guardian_session_is_reused_for_consecutive_tool_reviews_without_prewarm
),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test.config.permissions.windows_sandbox_private_desktop,
use_legacy_landlock: test.config.features.use_legacy_landlock(),
exec_policy: None,
@@ -838,6 +838,7 @@ impl ExecutorHookFixture {
),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&self.test.config),
windows_sandbox_type: self.test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: self
.test
.config
@@ -366,6 +366,7 @@ async fn skill_mcp_dependency_oauth_uses_configured_http_client() -> Result<()>
permission_profile: PermissionProfileSnapshot::legacy(PermissionProfile::Disabled),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&fixture.config),
windows_sandbox_type: fixture.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: fixture.config.permissions.windows_sandbox_private_desktop,
use_legacy_landlock: fixture.config.features.use_legacy_landlock(),
exec_policy: None,
@@ -497,6 +497,7 @@ async fn root_reconciliation_reuses_pending_apps_startup() -> Result<()> {
),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
@@ -2429,6 +2429,7 @@ async fn owner_network_policy_follows_the_selected_remote_command() -> Result<()
}),
shell_environment_policy: test.config.permissions.shell_environment_policy.clone(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
+8
View File
@@ -597,6 +597,7 @@ async fn environment_permissions_follow_configuration_ownership() -> Result<()>
permission_profile: owner_permission_profile,
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
@@ -1461,6 +1462,7 @@ async fn shared_executor_keeps_ready_capability_roots_scoped_to_each_attachment(
permission_profile: permission_profile.clone(),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
@@ -1506,6 +1508,7 @@ async fn shared_executor_keeps_ready_capability_roots_scoped_to_each_attachment(
permission_profile: permission_profile.clone(),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
@@ -1535,6 +1538,7 @@ async fn shared_executor_keeps_ready_capability_roots_scoped_to_each_attachment(
permission_profile: permission_profile.clone(),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
@@ -1603,6 +1607,7 @@ async fn shared_executor_keeps_ready_capability_roots_scoped_to_each_attachment(
permission_profile: permission_profile.clone(),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
@@ -1679,6 +1684,7 @@ async fn owner_network_policy_rejects_unsupported_environment_authority() -> Res
permission_profile: PermissionProfileSnapshot::legacy(PermissionProfile::Disabled),
shell_environment_policy: test.config.permissions.shell_environment_policy.clone(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test.config.permissions.windows_sandbox_private_desktop,
use_legacy_landlock: test.config.features.use_legacy_landlock(),
exec_policy: None,
@@ -1768,6 +1774,7 @@ async fn pending_attachment_installs_configuration_before_waiting_turn_resumes()
permission_profile: PermissionProfileSnapshot::legacy(PermissionProfile::read_only()),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test.config.permissions.windows_sandbox_private_desktop,
use_legacy_landlock: test.config.features.use_legacy_landlock(),
exec_policy: None,
@@ -2435,6 +2442,7 @@ async fn deferred_executor_spawn_agent_inherits_ready_step_environments(
),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test
.config
.permissions
+2
View File
@@ -828,6 +828,7 @@ async fn environment_mcp_policy_filters_runtime_config_and_model_tools(
),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&fixture.config),
windows_sandbox_type: fixture.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: fixture
.config
.permissions
@@ -1890,6 +1891,7 @@ async fn stdio_mcp_tool_call_includes_sandbox_state_meta(
),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&fixture.config),
windows_sandbox_type: fixture.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: fixture
.config
.permissions
@@ -700,6 +700,7 @@ async fn shell_snapshot_v2_guardian_uses_its_resolved_permissions_and_tools(
permission_profile: PermissionProfileSnapshot::legacy(PermissionProfile::Disabled),
shell_environment_policy: test.config.permissions.shell_environment_policy.clone(),
windows_sandbox_level: WindowsSandboxLevel::from_config(&test.config),
windows_sandbox_type: test.config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: test.config.permissions.windows_sandbox_private_desktop,
use_legacy_landlock: test.config.features.use_legacy_landlock(),
exec_policy: None,
@@ -505,6 +505,7 @@ async fn exec_command_uses_installed_environment_shell_policy_with_explicit_over
..Default::default()
},
windows_sandbox_level: WindowsSandboxLevel::from_config(&harness.test().config),
windows_sandbox_type: harness.test().config.permissions.windows_sandbox_type,
windows_sandbox_private_desktop: harness
.test()
.config
@@ -7,6 +7,7 @@ use codex_protocol::config_types::WindowsSandboxLevel;
use codex_protocol::models::PermissionProfile;
use codex_protocol::models::PermissionProfileSnapshot;
use codex_protocol::permissions::NetworkSandboxPolicy;
use codex_protocol::sandbox::SandboxType;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
#[cfg(windows)]
@@ -277,6 +278,7 @@ async fn workspace_roots_allow_file_and_command_writes_in_secondary_root(
),
shell_environment_policy: Default::default(),
windows_sandbox_level: WindowsSandboxLevel::RestrictedToken,
windows_sandbox_type: SandboxType::WindowsRestrictedToken,
windows_sandbox_private_desktop: test
.config
.permissions