Skip to content

fix: move arg0 handling out of codex-linux-sandbox and into its own crate#1697

Merged
bolinfest merged 1 commit into
mainfrom
pr1697
Jul 28, 2025
Merged

fix: move arg0 handling out of codex-linux-sandbox and into its own crate#1697
bolinfest merged 1 commit into
mainfrom
pr1697

Conversation

@bolinfest

@bolinfest bolinfest commented Jul 28, 2025

Copy link
Copy Markdown
Collaborator

We had existing logic that would check to see if arg0 is "codex-linux-sandbox", and if so, delegate to run_main() in the codex-linux-sandbox, which would set up the sandbox rules and then exec(3) the command to run under the sandbox:

/// Helper that consolidates the common boilerplate found in several Codex
/// binaries (`codex`, `codex-exec`, `codex-tui`) around dispatching to the
/// `codex-linux-sandbox` sub-command.
///
/// When the current executable is invoked through the hard-link or alias
/// named `codex-linux-sandbox` we *directly* execute [`run_main`](crate::run_main)
/// (which never returns). Otherwise we:
/// 1. Construct a Tokio multi-thread runtime.
/// 2. Derive the path to the current executable (so children can re-invoke
/// the sandbox) when running on Linux.
/// 3. Execute the provided async `main_fn` inside that runtime, forwarding
/// any error.
///
/// This function eliminates duplicated code across the various `main.rs`
/// entry-points.
pub fn run_with_sandbox<F, Fut>(main_fn: F) -> anyhow::Result<()>

This arg0 helper lived in the codex-linux-sandbox, but as it is a generally useful mechanism, it should be in its own crate, so this PR introduces the codex-arg0 crate and moves the code there. (I considered moving it into codex-common, but that ran the risk of circular dependencies, so it seemed easiest to move it into its own crate.)

This also enables us to tighten up some the dependencies for the codex-linux-sandbox crate, as now it has no [dependencies] section, as everything is now scoped to [target.'cfg(target_os = "linux")'.dependencies].


Stack created with Sapling. Best reviewed with ReviewStack.

@bolinfest bolinfest force-pushed the pr1697 branch 2 times, most recently from aa8fa29 to f078381 Compare July 28, 2025 03:33
@bolinfest bolinfest marked this pull request as ready for review July 28, 2025 03:40
@bolinfest bolinfest merged commit 9102255 into main Jul 28, 2025
11 checks passed
@bolinfest bolinfest deleted the pr1697 branch July 28, 2025 15:31
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 28, 2025
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