diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rs index 6156b9b9ea..5028357561 100644 --- a/codex-rs/core/src/config/config_tests.rs +++ b/codex-rs/core/src/config/config_tests.rs @@ -9540,6 +9540,37 @@ async fn explicit_sandbox_mode_falls_back_when_disallowed_by_requirements() -> s Ok(()) } +#[tokio::test] +async fn unset_windows_sandbox_mode_uses_requirements_default_without_warning() +-> std::io::Result<()> { + let codex_home = TempDir::new()?; + + let config = ConfigBuilder::without_managed_config_for_tests() + .codex_home(codex_home.path().to_path_buf()) + .fallback_cwd(Some(codex_home.path().to_path_buf())) + .cloud_config_bundle( + CloudConfigBundleFixture::loader_with_enterprise_requirement( + r#"[windows] +allowed_sandbox_implementations = ["elevated"] +"#, + ), + ) + .build() + .await?; + + assert_eq!( + config.permissions.windows_sandbox_mode, + Some(codex_config::types::WindowsSandboxModeToml::Elevated) + ); + assert!( + config.startup_warnings.iter().all(|warning| !warning + .contains("Configured value for `windows.sandbox` is disallowed by requirements")), + "{:?}", + config.startup_warnings + ); + Ok(()) +} + #[tokio::test] async fn windows_sandbox_mode_falls_back_when_disallowed_by_requirements() -> std::io::Result<()> { let codex_home = TempDir::new()?; diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rs index 54fbb97f69..4e704e3a14 100644 --- a/codex-rs/core/src/config/mod.rs +++ b/codex-rs/core/src/config/mod.rs @@ -3070,12 +3070,14 @@ impl Config { WindowsSandboxLevel::Disabled => None, } }); - apply_requirement_constrained_value( - "windows.sandbox", - selected_windows_sandbox_mode, - &mut constrained_windows_sandbox_mode, - &mut startup_warnings, - )?; + if let Some(selected_windows_sandbox_mode) = selected_windows_sandbox_mode { + apply_requirement_constrained_value( + "windows.sandbox", + Some(selected_windows_sandbox_mode), + &mut constrained_windows_sandbox_mode, + &mut startup_warnings, + )?; + } let effective_windows_sandbox_mode = *constrained_windows_sandbox_mode.get(); let windows_sandbox_mode = if constrained_windows_sandbox_mode.source.is_some() { effective_windows_sandbox_mode