Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Log Windows sandbox availability and backend selection (#51974)

iceweasel-oaiea27864f99f0
diff --git a/codex-rs/app-server/src/request_processors/windows_sandbox_processor.rs b/codex-rs/app-server/src/request_processors/windows_sandbox_processor.rs
index 50b6351b24..d22779fa70 100644
--- a/codex-rs/app-server/src/request_processors/windows_sandbox_processor.rs
+++ b/codex-rs/app-server/src/request_processors/windows_sandbox_processor.rs
@@ -19,6 +19,7 @@ impl WindowsSandboxRequestProcessor {
config: Arc<Config>,
config_manager: ConfigManager,
) -> Self {
+ codex_core::windows_sandbox::log_windows_sandbox_startup(&config);
Self {
outgoing,
config,
diff --git a/codex-rs/app-server/tests/suite/v2/remote_thread_store.rs b/codex-rs/app-server/tests/suite/v2/remote_thread_store.rs
index 34883c89d0..c7b7545d6e 100644
--- a/codex-rs/app-server/tests/suite/v2/remote_thread_store.rs
+++ b/codex-rs/app-server/tests/suite/v2/remote_thread_store.rs
@@ -711,9 +711,12 @@ fn assert_no_local_persistence_artifacts(codex_home: &Path) -> Result<()> {
"non-local thread persistence should not create sqlite artifacts: {sqlite_artifacts:?}"
);
let mut entries = codex_home_entries(codex_home)?;
- // Host startup may leave sandbox migration markers, and Bazel test runs may
- // initialize shell snapshot storage. Neither is thread persistence.
+ // Host startup may leave sandbox migration markers or Windows sandbox logs,
+ // and Bazel test runs may initialize shell snapshot storage. None is thread
+ // persistence.
entries.remove(".sandbox_migration");
+ #[cfg(windows)]
+ entries.remove(".sandbox");
entries.remove("shell_snapshots");
assert_eq!(
entries,
diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rs
index 537fcf4ca4..e4face0152 100644
--- a/codex-rs/core/src/session/mod.rs
+++ b/codex-rs/core/src/session/mod.rs
@@ -903,6 +903,7 @@ impl Session {
session_configuration
.validate(&environment_selections)
.map_err(|err| CodexErr::InvalidRequest(err.to_string()))?;
+ crate::windows_sandbox::log_windows_sandbox_startup(&config);
// Generate a unique ID for the lifetime of this session.
let session_source_clone = session_configuration.session_source.clone();
@@ -1933,6 +1934,7 @@ impl Session {
should_commit: impl FnOnce(&SessionConfiguration, &SessionConfiguration) -> bool + Send,
) -> ConstraintResult<Option<SessionSettingsCommit>> {
let notify_config_contributors = !self.services.extensions.config_contributors().is_empty();
+ let windows_sandbox_changed;
let (commit, previous_config, new_config, permission_profile_changed, mcp_inputs_changed) = {
let mut state = self.state.lock().await;
let updated = match self.apply_session_settings(&state.session_configuration, &updates)
@@ -1962,6 +1964,8 @@ impl Session {
self.mark_mcp_runtime_dirty();
}
// Save new environment defaults for future turns. The running turn keeps its own.
+ windows_sandbox_changed =
+ state.session_configuration.windows_sandbox_level != updated.windows_sandbox_level;
state.session_configuration = updated;
if root_service_tier_changed {
self.services.agent_control.propagate_config_update(
@@ -1990,6 +1994,13 @@ impl Session {
mcp_inputs_changed,
)
};
+ if windows_sandbox_changed {
+ crate::windows_sandbox::log_windows_sandbox_change(
+ commit.configuration.codex_home.as_path(),
+ commit.configuration.windows_sandbox_type,
+ commit.configuration.windows_sandbox_level,
+ );
+ }
self.emit_config_changed_contributors(previous_config.as_ref(), new_config.as_ref());
if permission_profile_changed {
self.refresh_managed_network_proxy_for_current_permission_profile()
diff --git a/codex-rs/core/src/windows_sandbox.rs b/codex-rs/core/src/windows_sandbox.rs
index 316e9ff7fc..2c2d1fdb36 100644
--- a/codex-rs/core/src/windows_sandbox.rs
+++ b/codex-rs/core/src/windows_sandbox.rs
@@ -1,3 +1,5 @@
+//! Windows sandbox configuration, runtime policy, and lifecycle diagnostics.
+
use crate::config::Config;
use crate::config::edit::ConfigEditsBuilder;
use codex_config::config_toml::ConfigToml;
@@ -18,6 +20,67 @@ use std::path::Path;
use std::path::PathBuf;
use std::time::Instant;
+/// Records local MXC availability and the selected backend at startup.
+pub fn log_windows_sandbox_startup(config: &Config) {
+ #[cfg(windows)]
+ {
+ let sandbox_dir = codex_windows_sandbox::sandbox_dir(config.codex_home.as_path());
+ let _ = std::fs::create_dir_all(&sandbox_dir);
+ let available = codex_sandboxing::windows_mxc_available();
+ codex_windows_sandbox::log_note(
+ &format!("MXC availability: {available}"),
+ Some(&sandbox_dir),
+ );
+ log_windows_sandbox_selection(
+ config.codex_home.as_path(),
+ config.effective_local_windows_sandbox_type(),
+ WindowsSandboxLevel::from_config(config),
+ );
+ }
+ #[cfg(not(windows))]
+ let _ = config;
+}
+
+/// Records the local backend after an accepted selection change.
+pub(crate) fn log_windows_sandbox_change(
+ codex_home: &Path,
+ sandbox_type: SandboxType,
+ sandbox_level: WindowsSandboxLevel,
+) {
+ #[cfg(windows)]
+ {
+ let codex_home = codex_home.to_owned();
+ tokio::task::spawn_blocking(move || {
+ log_windows_sandbox_selection(&codex_home, sandbox_type, sandbox_level);
+ });
+ }
+ #[cfg(not(windows))]
+ let _ = (codex_home, sandbox_type, sandbox_level);
+}
+
+#[cfg(windows)]
+fn log_windows_sandbox_selection(
+ codex_home: &Path,
+ sandbox_type: SandboxType,
+ sandbox_level: WindowsSandboxLevel,
+) {
+ let backend = if sandbox_type == SandboxType::WindowsMxc {
+ "mxc"
+ } else {
+ match sandbox_level {
+ WindowsSandboxLevel::Disabled => "disabled",
+ WindowsSandboxLevel::RestrictedToken => "unelevated",
+ WindowsSandboxLevel::Elevated => "elevated",
+ }
+ };
+ let sandbox_dir = codex_windows_sandbox::sandbox_dir(codex_home);
+ let _ = std::fs::create_dir_all(&sandbox_dir);
+ codex_windows_sandbox::log_note(
+ &format!("Windows sandbox selection: {backend}"),
+ Some(&sandbox_dir),
+ );
+}
+
/// Selects local binding policy from the sandbox and executor OS.
pub fn local_binding_policy_for_sandbox(
sandbox_type: SandboxType,