fix: overhaul how we spawn commands under seccomp/landlock on Linux

This commit is contained in:
Michael Bolin
2025-05-22 15:30:18 -07:00
parent cb379d7797
commit 4fc56ca54b
18 changed files with 341 additions and 280 deletions
+1
View File
@@ -20,6 +20,7 @@ chrono = "0.4.40"
clap = { version = "4", features = ["derive"] }
codex-core = { path = "../core" }
codex-common = { path = "../common", features = ["cli", "elapsed"] }
codex-linux-sandbox = { path = "../linux-sandbox" }
mcp-types = { path = "../mcp-types" }
owo-colors = "4.2.0"
serde_json = "1"
+29 -5
View File
@@ -1,11 +1,35 @@
//! Entry-point for the `codex-exec` binary.
//!
//! When invoked normally it parses the standard `codex-exec` CLI options and
//! launches the non-interactive Codex agent. However, if the executable name is
//! `codex-linux-sandbox`, we instead treat the invocation as a request to run a
//! *sandboxed* command under Landlock + seccomp. This allows us to create a
//! lightweight symlink alias instead of shipping a separate binary — mirroring
//! how macOS uses `/usr/bin/sandbox-exec`.
use clap::Parser;
use codex_exec::Cli;
use codex_exec::run_main;
use std::path::Path;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
run_main(cli).await?;
// No #[tokio::main]! If arg0 is `codex-linux-sandbox`, we delegate to
// `codex_linux_sandbox::run_main()` and do not want to start the Tokio runtime.
fn main() -> anyhow::Result<()> {
// Determine if we were invoked via the special alias.
let argv0 = std::env::args().next().unwrap_or_default();
let exe_name = Path::new(&argv0)
.file_name()
.and_then(|s| s.to_str())
.unwrap_or("");
Ok(())
if exe_name == "codex-linux-sandbox" {
codex_linux_sandbox::run_main()
}
// Regular `codex-exec` invocation – parse the normal CLI.
let runtime = tokio::runtime::Runtime::new()?;
runtime.block_on(async {
let cli = Cli::parse();
run_main(cli).await?;
Ok(())
})
}