Skip to content

Move unified-exec sandbox launch to exec-server#16736

Open
starr-openai wants to merge 28 commits intomainfrom
exec-server-sandbox-0403
Open

Move unified-exec sandbox launch to exec-server#16736
starr-openai wants to merge 28 commits intomainfrom
exec-server-sandbox-0403

Conversation

@starr-openai
Copy link
Copy Markdown
Contributor

Summary

  • add a shared SandboxLaunchConfig that can be serialized across the exec-server protocol
  • move remote unified-exec sandbox argv construction into codex-exec-server
  • keep zsh-fork and managed-network gaps explicit with TODOs while preserving current behavior

Validation

  • just fmt
  • remote via codex-applied-devbox: cargo test -p codex-exec-server
  • remote via codex-applied-devbox: cargo test -p codex-sandboxing
  • remote via codex-applied-devbox: cargo test -p codex-core unified_exec
  • remote Docker smoke against containerized exec-server: verified sandbox=None -> SandboxType::None, auto selects LinuxSeccomp when policy requires it, and require forces LinuxSeccomp across env boundary (restrictive auto case in Docker still depends on host kernel userns support)

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: 13c8fde3cf

ℹ️ 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".

Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai left a comment

Choose a reason for hiding this comment

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

  1. Reduce complexity in codex-sandboxing if possible
  2. Use codex_arg0 to figure out the linux sandbox path
  3. Use single code path in unified exec, fail when using zsh/additional permissions with remote.

@starr-openai starr-openai requested a review from pakrym-oai April 7, 2026 20:30
starr-openai added a commit that referenced this pull request Apr 7, 2026
Co-authored-by: Codex <noreply@openai.com>
starr-openai added a commit that referenced this pull request Apr 7, 2026
Co-authored-by: Codex <noreply@openai.com>
@starr-openai starr-openai force-pushed the exec-server-sandbox-0403 branch from ce6f444 to 0695fe1 Compare April 7, 2026 21:36
@starr-openai starr-openai force-pushed the exec-server-sandbox-0403 branch from c02a60d to c5942d9 Compare April 8, 2026 17:58
Use /bin/sh for the PTY/stdin and write-denial probes so the tests do not depend on /usr/bin/python3 being usable on macOS Bazel runners.

Co-authored-by: Codex <noreply@openai.com>
@starr-openai starr-openai force-pushed the exec-server-sandbox-0403 branch from 5681137 to 0e02bcc Compare April 8, 2026 21:32
run_main_with_listen_url(DEFAULT_LISTEN_URL).await
}

pub async fn run_main_with_listen_url(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

delete this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 8cf18dc. I removed the unused run_main_with_listen_url() wrapper/export, updated run_main() to call run_main_with_runtime(DEFAULT_LISTEN_URL, ...) directly, and fixed the README export list to point at run_main_with_runtime().

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

doesn't actually look like it's removed

@starr-openai starr-openai force-pushed the exec-server-sandbox-0403 branch from 0e02bcc to 8cf18dc Compare April 8, 2026 21:59
@starr-openai starr-openai force-pushed the exec-server-sandbox-0403 branch from 8cf18dc to 66b06cc Compare April 8, 2026 22:06
@starr-openai starr-openai force-pushed the exec-server-sandbox-0403 branch from 66b06cc to c2596cc Compare April 8, 2026 22:11
Prepare sandbox env inside the sandbox transform result so core and exec-server do not have to mutate the request at their spawn boundaries.

Co-authored-by: Codex <noreply@openai.com>
@starr-openai starr-openai force-pushed the exec-server-sandbox-0403 branch from c2596cc to 61500ee Compare April 8, 2026 22:18
Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai left a comment

Choose a reason for hiding this comment

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

My main q is whether we can maintain a single execution path like we do today (even if some features like network don't work over the remote executor).

Then there are also some non obvious changes to sandboxing logic like moving where env vars are set and how the preference is used.

@starr-openai
Copy link
Copy Markdown
Contributor Author

Responding to the latest review summary: I pushed 61500ee to make the sandboxing pieces less surprising. Normal core/exec-server launches now pass SandboxablePreference::Auto and let SandboxManager::transform() select the platform sandbox; the public SandboxablePreference::from_selected_sandbox() adapter is gone. The env var prep still has one owner: SandboxExecRequest::prepare_env_for_spawn() inside the manager transform result. The only forced preference left is internal to SandboxAttempt, where the orchestrator is intentionally retrying a concrete sandboxed/non-sandboxed attempt.

On the single execution path question: this PR now shares the sandbox transform path via SandboxLaunchConfig + SandboxManager::transform(), but I have not collapsed local unified-exec process spawning through exec-server in this review-fix commit. The local fallback still owns the zsh-fork/StdoutStream/inherited-fd spawn lifecycle. I think the clean next step is to move those local-spawn features behind ExecBackend; doing that here would be a broader local-spawn migration than the sandbox-transform cleanup.

Co-authored-by: Codex <noreply@openai.com>
@starr-openai starr-openai force-pushed the exec-server-sandbox-0403 branch from 8ddfba8 to 59cf717 Compare April 8, 2026 22:46
Co-authored-by: Codex <noreply@openai.com>
// Safety: [`run_main`] never returns.
codex_linux_sandbox::run_main();
} else if exe_name == APPLY_PATCH_ARG0 || exe_name == MISSPELLED_APPLY_PATCH_ARG0 {
codex_linux_sandbox::dispatch_if_requested();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why did this have to change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this doesn't strictly need to change - the main thing was to pull codex_linux_sandbox::dispatch_if_requested() so we can call that from the exec-server main, and thi sjust re-uses the same function.

Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai Apr 9, 2026

Choose a reason for hiding this comment

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

why can't we use the entire arg0_dispatch_or_else as every other entrypoint does?

Copy link
Copy Markdown
Collaborator

@pakrym-oai pakrym-oai Apr 9, 2026

Choose a reason for hiding this comment

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

I think we need to split exec-server bin and lib to avoid the cicrular dependency. And use the existing pattern.

.turn
.environment
.as_ref()
.filter(|environment| environment.exec_server_url().is_some())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we already have this fork in

if environment.is_remote() {

I don't think we should add another fork and another entry point to remote exec

}

impl<'a> SandboxAttempt<'a> {
pub(crate) fn sandbox_preference(&self) -> SandboxablePreference {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same comment as before, we select sandbox type based on preference, feels a bit sus to do the reverse. Are you sure having htis method makes sense?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should SandboxAttempt store preference directly instead?

env: Default::default(),
tty: false,
arg0: None,
sandbox: SandboxLaunchConfig::no_sandbox(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do you agree with codex that special SandboxLaunchConfig is better than Option<SandboxLaunchConfig> pattern that we used for Fs abstraction?

}

#[cfg(target_os = "linux")]
pub fn dispatch_if_requested() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we should break the circular dependency in a separte pr and keep arg0/sandboxing code as is.

pub windows_sandbox_level: WindowsSandboxLevel,
pub windows_sandbox_private_desktop: bool,
impl SandboxExecRequest {
pub fn prepare_env_for_spawn(&mut self) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is the reason this had to move?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants