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

+6 -6
View File
@@ -287,12 +287,12 @@ The origin of a required `chatgpt_base_url` must match the discovered origin by
## Windows sandbox implementation selection
`windowsSandbox/setupStart` and `windowsSandbox/readiness` apply only to the
legacy `elevated` and `unelevated` backends. Clients resolve the desired sandbox
implementation from configuration. When it is `mxc`, they skip both methods;
`allowedWindowsSandboxImplementations` can allow `mxc` independently of the
legacy setup modes. Non-Windows hosts report `notConfigured` for the legacy
readiness API.
`windowsSandbox/setupStart` applies only to the legacy `elevated` and
`unelevated` backends. `windowsSandbox/readiness` reports `ready` when MXC is
selected so clients do not offer legacy setup. The
`allowedWindowsSandboxImplementations` requirement governs only the legacy
backends and does not restrict MXC. Its `mxc` enum member is retained for wire
compatibility but is not emitted. Non-Windows hosts report `notConfigured`.
MXC uses the standard `command/exec` streaming and process-control path, including
ConPTY when `tty` is enabled. The buffered legacy Windows sandbox restrictions on
@@ -320,6 +320,7 @@ impl CommandExecRequestProcessor {
windows_sandbox_workspace_roots.as_slice(),
&codex_linux_sandbox_exe,
&self.arg0_paths.codex_self_exe,
self.config.permissions.windows_sandbox_type,
use_legacy_landlock,
)
.map_err(|err| internal_error(format!("exec failed: {err}")))?;
@@ -472,10 +472,10 @@ fn map_requirements_to_api(
implementations
.into_iter()
.map(|implementation| match implementation {
codex_config::types::WindowsSandboxModeToml::Elevated => {
codex_config::WindowsSandboxImplementationToml::Elevated => {
WindowsSandboxImplementation::Elevated
}
codex_config::types::WindowsSandboxModeToml::Unelevated => {
codex_config::WindowsSandboxImplementationToml::Unelevated => {
WindowsSandboxImplementation::Unelevated
}
})
@@ -1102,8 +1102,8 @@ mod tests {
let mapped = map_test_requirements(ConfigRequirementsToml {
windows: Some(WindowsRequirementsToml {
allowed_sandbox_implementations: Some(vec![
codex_config::types::WindowsSandboxModeToml::Elevated,
codex_config::types::WindowsSandboxModeToml::Unelevated,
codex_config::WindowsSandboxImplementationToml::Elevated,
codex_config::WindowsSandboxImplementationToml::Unelevated,
]),
sandbox_private_desktop: Some(false),
}),
@@ -21,6 +21,7 @@ use codex_app_server_protocol::ThreadSection;
use codex_app_server_protocol::ThreadSectionAppearance;
use codex_app_server_protocol::ThreadSectionMoveParams;
use codex_app_server_protocol::ThreadSectionMoveResponse;
use codex_config::types::WindowsSandboxModeToml;
use codex_extension_api::ExtensionDataInit;
use codex_extension_api::ThreadIdleCause;
use codex_protocol::SanitizedGitUrl;
@@ -4931,18 +4932,17 @@ impl ThreadRequestProcessor {
// Persist Windows sandbox mode.
let mut cli_overrides = cli_overrides.unwrap_or_default();
if cfg!(windows) {
match WindowsSandboxLevel::from_config(&self.config) {
WindowsSandboxLevel::Elevated => {
cli_overrides
.insert("windows.sandbox".to_string(), serde_json::json!("elevated"));
let mode = self.config.permissions.windows_sandbox_mode.or_else(|| {
match WindowsSandboxLevel::from_config(&self.config) {
WindowsSandboxLevel::Elevated => Some(WindowsSandboxModeToml::Elevated),
WindowsSandboxLevel::RestrictedToken => {
Some(WindowsSandboxModeToml::Unelevated)
}
WindowsSandboxLevel::Disabled => None,
}
WindowsSandboxLevel::RestrictedToken => {
cli_overrides.insert(
"windows.sandbox".to_string(),
serde_json::json!("unelevated"),
);
}
WindowsSandboxLevel::Disabled => {}
});
if let Some(mode) = mode {
cli_overrides.insert("windows.sandbox".to_string(), serde_json::json!(mode));
}
}
let request_overrides = if cli_overrides.is_empty() {
@@ -1,6 +1,7 @@
use super::*;
#[cfg(target_os = "windows")]
use anyhow::Context as _;
use codex_protocol::sandbox::SandboxType;
use codex_utils_path_uri::PathUri;
#[derive(Clone)]
@@ -305,6 +306,12 @@ fn determine_windows_sandbox_readiness(config: &Config) -> WindowsSandboxReadine
};
}
if config.permissions.windows_sandbox_type == SandboxType::WindowsMxc {
return WindowsSandboxReadinessResponse {
status: WindowsSandboxReadiness::Ready,
};
}
determine_windows_sandbox_readiness_from_state(
WindowsSandboxLevel::from_config(config),
sandbox_setup_is_complete(config.codex_home.as_path()),