From e622ab400dcab2babdd0d8b69063ceb26687568c Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Tue, 29 Apr 2025 16:59:48 -0700 Subject: [PATCH] feat: codex-linux-sandbox standalone executable --- codex-rs/cli/Cargo.toml | 8 ++++++ codex-rs/cli/src/landlock.rs | 5 +--- codex-rs/cli/src/lib.rs | 35 ++++++++++++++++++++++++ codex-rs/cli/src/linux-sandbox/main.rs | 4 +++ codex-rs/cli/src/main.rs | 37 +++----------------------- codex-rs/cli/src/seatbelt.rs | 2 +- 6 files changed, 53 insertions(+), 38 deletions(-) create mode 100644 codex-rs/cli/src/lib.rs create mode 100644 codex-rs/cli/src/linux-sandbox/main.rs diff --git a/codex-rs/cli/Cargo.toml b/codex-rs/cli/Cargo.toml index c160942980..6a3a3593b9 100644 --- a/codex-rs/cli/Cargo.toml +++ b/codex-rs/cli/Cargo.toml @@ -7,6 +7,14 @@ edition = "2021" name = "codex" path = "src/main.rs" +[[bin]] +name = "codex-linux-sandbox" +path = "src/linux-sandbox/main.rs" + +[lib] +name = "codex_cli" +path = "src/lib.rs" + [dependencies] anyhow = "1" clap = { version = "4", features = ["derive"] } diff --git a/codex-rs/cli/src/landlock.rs b/codex-rs/cli/src/landlock.rs index b57591bfe7..f663889795 100644 --- a/codex-rs/cli/src/landlock.rs +++ b/codex-rs/cli/src/landlock.rs @@ -11,10 +11,7 @@ use std::process::ExitStatus; /// Execute `command` in a Linux sandbox (Landlock + seccomp) the way Codex /// would. -pub(crate) fn run_landlock( - command: Vec, - sandbox_policy: SandboxPolicy, -) -> anyhow::Result<()> { +pub fn run_landlock(command: Vec, sandbox_policy: SandboxPolicy) -> anyhow::Result<()> { if command.is_empty() { anyhow::bail!("command args are empty"); } diff --git a/codex-rs/cli/src/lib.rs b/codex-rs/cli/src/lib.rs new file mode 100644 index 0000000000..707798874d --- /dev/null +++ b/codex-rs/cli/src/lib.rs @@ -0,0 +1,35 @@ +#[cfg(target_os = "linux")] +mod landlock; +pub mod proto; +pub mod seatbelt; + +use clap::Parser; +use codex_core::SandboxPermissionOption; + +#[derive(Debug, Parser)] +pub struct SeatbeltCommand { + /// Convenience alias for low-friction sandboxed automatic execution (network-disabled sandbox that can write to cwd and TMPDIR) + #[arg(long = "full-auto", default_value_t = false)] + pub full_auto: bool, + + #[clap(flatten)] + pub sandbox: SandboxPermissionOption, + + /// Full command args to run under seatbelt. + #[arg(trailing_var_arg = true)] + pub command: Vec, +} + +#[derive(Debug, Parser)] +pub struct LandlockCommand { + /// Convenience alias for low-friction sandboxed automatic execution (network-disabled sandbox that can write to cwd and TMPDIR) + #[arg(long = "full-auto", default_value_t = false)] + pub full_auto: bool, + + #[clap(flatten)] + pub sandbox: SandboxPermissionOption, + + /// Full command args to run under landlock. + #[arg(trailing_var_arg = true)] + pub command: Vec, +} diff --git a/codex-rs/cli/src/linux-sandbox/main.rs b/codex-rs/cli/src/linux-sandbox/main.rs new file mode 100644 index 0000000000..a4a8dbf67f --- /dev/null +++ b/codex-rs/cli/src/linux-sandbox/main.rs @@ -0,0 +1,4 @@ +#[tokio::main] +async fn main() -> anyhow::Result<()> { + unimplemented!() +} diff --git a/codex-rs/cli/src/main.rs b/codex-rs/cli/src/main.rs index ba6b15d99f..d0f9814256 100644 --- a/codex-rs/cli/src/main.rs +++ b/codex-rs/cli/src/main.rs @@ -1,9 +1,8 @@ -#[cfg(target_os = "linux")] -mod landlock; -mod proto; -mod seatbelt; - use clap::Parser; +use codex_cli::proto; +use codex_cli::seatbelt; +use codex_cli::LandlockCommand; +use codex_cli::SeatbeltCommand; use codex_core::protocol::SandboxPolicy; use codex_core::SandboxPermissionOption; use codex_exec::Cli as ExecCli; @@ -63,34 +62,6 @@ enum DebugCommand { Landlock(LandlockCommand), } -#[derive(Debug, Parser)] -struct SeatbeltCommand { - /// Convenience alias for low-friction sandboxed automatic execution (network-disabled sandbox that can write to cwd and TMPDIR) - #[arg(long = "full-auto", default_value_t = false)] - full_auto: bool, - - #[clap(flatten)] - pub sandbox: SandboxPermissionOption, - - /// Full command args to run under seatbelt. - #[arg(trailing_var_arg = true)] - command: Vec, -} - -#[derive(Debug, Parser)] -struct LandlockCommand { - /// Convenience alias for low-friction sandboxed automatic execution (network-disabled sandbox that can write to cwd and TMPDIR) - #[arg(long = "full-auto", default_value_t = false)] - full_auto: bool, - - #[clap(flatten)] - sandbox: SandboxPermissionOption, - - /// Full command args to run under landlock. - #[arg(trailing_var_arg = true)] - command: Vec, -} - #[derive(Debug, Parser)] struct ReplProto {} diff --git a/codex-rs/cli/src/seatbelt.rs b/codex-rs/cli/src/seatbelt.rs index f4a8edde00..6c49d8cc7e 100644 --- a/codex-rs/cli/src/seatbelt.rs +++ b/codex-rs/cli/src/seatbelt.rs @@ -1,7 +1,7 @@ use codex_core::exec::create_seatbelt_command; use codex_core::protocol::SandboxPolicy; -pub(crate) async fn run_seatbelt( +pub async fn run_seatbelt( command: Vec, sandbox_policy: SandboxPolicy, ) -> anyhow::Result<()> {