Skip to content

use long-lived sessions for codex sandbox windows#18953

Merged
iceweasel-oai merged 4 commits intomainfrom
codex/sandbox-cmd-windows-sessions
Apr 22, 2026
Merged

use long-lived sessions for codex sandbox windows#18953
iceweasel-oai merged 4 commits intomainfrom
codex/sandbox-cmd-windows-sessions

Conversation

@iceweasel-oai
Copy link
Copy Markdown
Collaborator

codex sandbox windows previously did a one-shot spawn for all commands.
This change uses the unified_exec session to spawn long-lived processes instead, and implements a simple bridge to forward stdin to the spawned session and stdout/stderr from the spawned session back to the caller.

It also fixes a bug with the new shared spawn context code where the "no-network env" was being applied to both elevated and unelevated sandbox spawns. It should only be applied for the unelevated sandbox because the elevated one uses firewall rules instead of an env-based network suppression strategy.

Comment thread codex-rs/cli/src/debug_sandbox.rs Outdated
)
}
})
run_command_under_windows_session(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just pulling the windows part into its own function because it's kinda big

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: faa44d3aca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/cli/src/debug_sandbox.rs
Comment on lines +305 to +319
spawn_windows_sandbox_session_elevated(
policy_str.as_str(),
sandbox_policy_cwd.as_path(),
config.codex_home.as_path(),
command,
cwd.as_path(),
env,
None,
/*tty*/ false,
/*stdin_open*/ true,
config.permissions.windows_sandbox_private_desktop,
)
.await
} else {
spawn_windows_sandbox_session_legacy(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly these spawn_windows_sandbox_session_* changes are the key part. They use the same backend as unified_exec will use instead of the previous "one and done" spawn approach

};

stdin_close_task.abort();
let _ = tokio::time::timeout(output_drain_timeout, async {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is just waiting for stdout/stderr from the child process to drain after we receive its exit code

add_git_safe_directory,
)?;
if should_apply_network_block(&common.policy) {
apply_no_network_to_env(env_map)?;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply the "no network" changes to the env here, only in the legacy function, not the elevated one

Copy link
Copy Markdown
Collaborator

@aaronl-openai aaronl-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

when I have my windows machine tomorrow I'll test this against my changes to make sure everything works together

@iceweasel-oai iceweasel-oai enabled auto-merge (squash) April 22, 2026 06:15
@iceweasel-oai iceweasel-oai merged commit 3a451b6 into main Apr 22, 2026
25 checks passed
@iceweasel-oai iceweasel-oai deleted the codex/sandbox-cmd-windows-sessions branch April 22, 2026 06:39
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants