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

+1 -1
View File
@@ -104,7 +104,7 @@ impl App {
windows_sandbox_ready(app_server).await;
}
let show_nux = std::mem::take(&mut self.windows_sandbox.prompt_after_trust)
&& self.chat_widget.windows_sandbox_config.mode.is_none()
&& !self.chat_widget.windows_sandbox_config.is_enabled()
|| self.chat_widget.windows_sandbox_config.requires_elevated();
if self.windows_sandbox_setup_is_local() {
self.chat_widget.maybe_prompt_windows_sandbox_enable(
+1
View File
@@ -1666,6 +1666,7 @@ async fn windows_sandbox_config_refresh_uses_connected_server() -> Result<()> {
Some(codex_app_server_protocol::WindowsSandboxSetupMode::Elevated);
assert!(app.refresh_windows_sandbox_config(&server).await);
let loaded_config = crate::windows_sandbox::WindowsSandboxConfig {
mxc_selected: false,
mode: Some(codex_app_server_protocol::WindowsSandboxSetupMode::Unelevated),
requirements: Some(None),
};
@@ -368,7 +368,7 @@ impl ChatWidget {
// cannot be set up from this TUI's Windows account.
return apply_actions();
}
if self.windows_sandbox_config.level() == WindowsSandboxLevel::Disabled {
if !self.windows_sandbox_config.is_enabled() {
let preset = preset.clone();
return vec![Box::new(move |tx| {
tx.send(AppEvent::OpenWindowsSandboxEnablePrompt {
@@ -64,7 +64,7 @@ impl ChatWidget {
| crate::app::WindowsSandboxHost::Unknown
) || (self.windows_sandbox_host != crate::app::WindowsSandboxHost::Remote
&& reviewer == ApprovalsReviewer::User
&& self.windows_sandbox_config.level() == WindowsSandboxLevel::Disabled))
&& !self.windows_sandbox_config.is_enabled()))
{
continue;
}
@@ -272,8 +272,7 @@ impl ChatWidget {
#[cfg(target_os = "windows")]
pub(crate) fn maybe_prompt_windows_sandbox_enable(&mut self, show_now: bool) {
let windows_sandbox_level = self.windows_sandbox_config.level();
let setup_is_required = windows_sandbox_level == WindowsSandboxLevel::Disabled
let setup_is_required = !self.windows_sandbox_config.is_enabled()
|| self.elevated_windows_sandbox_setup_required();
if show_now
&& setup_is_required
@@ -18,8 +18,6 @@ use codex_app_server_protocol::RequestId;
use codex_app_server_protocol::ServerNotification;
use codex_exec_server::LOCAL_FS;
use codex_git_utils::resolve_root_git_project_for_trust;
#[cfg(target_os = "windows")]
use codex_protocol::config_types::WindowsSandboxLevel;
use crossterm::event::KeyCode;
use crossterm::event::KeyEvent;
use crossterm::event::KeyEventKind;
@@ -149,7 +147,7 @@ impl OnboardingScreen {
config.cwd.display().to_string(),
)
.await
.is_ok_and(|state| state.level() == WindowsSandboxLevel::Disabled)
.is_ok_and(|state| !state.is_enabled())
} else {
false
};
+20 -6
View File
@@ -12,6 +12,7 @@ use uuid::Uuid;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub(crate) struct WindowsSandboxConfig {
pub(crate) mxc_selected: bool,
pub(crate) mode: Option<WindowsSandboxSetupMode>,
// None means policy has not been loaded; a loaded null list allows both modes.
pub(crate) requirements: Option<Option<Vec<WindowsSandboxSetupMode>>>,
@@ -23,14 +24,22 @@ impl WindowsSandboxConfig {
config: &ConfigReadResponse,
requirements: ConfigRequirementsReadResponse,
) -> Self {
let configured_sandbox = config
.config
.additional
.get("windows")
.and_then(|windows| windows.get("sandbox"));
let mxc_selected = configured_sandbox
.and_then(|implementation| serde_json::from_value(implementation.clone()).ok())
== Some(WindowsSandboxImplementation::Mxc);
let mut state = Self {
mode: config
.config
.additional
.get("windows")
.and_then(|windows| windows.get("sandbox"))
mxc_selected,
mode: configured_sandbox
.and_then(|mode| serde_json::from_value(mode.clone()).ok())
.or_else(|| {
if mxc_selected {
return None;
}
let features = config.config.additional.get("features")?;
[
(
@@ -72,7 +81,8 @@ impl WindowsSandboxConfig {
}),
),
};
if let Some(Some(allowed)) = &state.requirements
if !state.mxc_selected
&& let Some(Some(allowed)) = &state.requirements
&& !state.mode.is_some_and(|mode| allowed.contains(&mode))
{
// Managed requirements prefer elevated when the configured value is disallowed.
@@ -86,6 +96,10 @@ impl WindowsSandboxConfig {
state
}
pub(crate) fn is_enabled(&self) -> bool {
self.mxc_selected || self.mode.is_some()
}
pub(crate) fn level(&self) -> WindowsSandboxLevel {
match self.mode {
Some(WindowsSandboxSetupMode::Elevated) => WindowsSandboxLevel::Elevated,
+19 -9
View File
@@ -11,36 +11,45 @@ fn windows_sandbox_server_policy_controls_setup_choices() {
Some("unelevated"),
serde_json::Value::Null,
Some(Unelevated),
(true, true, false),
(true, true, false, true),
),
(
Some("unelevated"),
json!(["elevated"]),
Some(Elevated),
(true, false, true),
(true, false, true, true),
),
(
None,
json!(["unelevated", "elevated"]),
Some(Elevated),
(true, true, true),
(true, true, true, true),
),
(
None,
json!(["unelevated"]),
Some(Unelevated),
(false, true, false),
(false, true, false, true),
),
(Some("unelevated"), json!([]), None, (false, false, false)),
(
Some("unelevated"),
json!(["mxc"]),
json!([]),
None,
(false, false, false),
(false, false, false, false),
),
(
Some("mxc"),
json!(["elevated"]),
None,
(true, false, false, true),
),
] {
let config = serde_json::from_value(json!({
"config": {"windows": {"sandbox": configured}}, "origins": {}
"config": {
"windows": {"sandbox": configured},
"features": {"elevated_windows_sandbox": configured == Some("mxc")}
},
"origins": {}
}))
.unwrap();
let requirements = serde_json::from_value(json!({
@@ -53,7 +62,8 @@ fn windows_sandbox_server_policy_controls_setup_choices() {
(
state.allows(Elevated),
state.allows(Unelevated),
state.requires_elevated()
state.requires_elevated(),
state.is_enabled(),
),
expected
);