mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
fix: overhaul how we spawn commands under seccomp/landlock on Linux
This commit is contained in:
@@ -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"
|
||||
|
||||
+38
-12
@@ -1,19 +1,45 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
//! Entry-point for the `codex-exec` binary.
|
||||
//!
|
||||
//! When this CLI is invoked normally, it parses the standard `codex-exec` CLI
|
||||
//! options and launches the non-interactive Codex agent. However, if it is
|
||||
//! invoked with arg0 as `codex-linux-sandbox`, we instead treat the invocation
|
||||
//! as a request to run the logic for the standalone `codex-linux-sandbox`
|
||||
//! executable (i.e., parse any -s args and then run a *sandboxed* command under
|
||||
//! Landlock + seccomp.
|
||||
//!
|
||||
//! This allows us to ship a completely separate set of functionality as part
|
||||
//! of the `codex-exec` binary.
|
||||
use clap::Parser;
|
||||
use codex_exec::Cli;
|
||||
use codex_exec::run_main;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let codex_linux_sandbox_exe: Option<PathBuf> = if cfg!(target_os = "linux") {
|
||||
std::env::current_exe().ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
// 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("");
|
||||
|
||||
let cli = Cli::parse();
|
||||
run_main(cli, codex_linux_sandbox_exe).await?;
|
||||
if exe_name == "codex-linux-sandbox" {
|
||||
codex_linux_sandbox::run_main()
|
||||
}
|
||||
|
||||
Ok(())
|
||||
// Regular `codex-exec` invocation – parse the normal CLI.
|
||||
let runtime = tokio::runtime::Runtime::new()?;
|
||||
runtime.block_on(async {
|
||||
let codex_linux_sandbox_exe: Option<PathBuf> = if cfg!(target_os = "linux") {
|
||||
std::env::current_exe().ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let cli = Cli::parse();
|
||||
run_main(cli, codex_linux_sandbox_exe).await?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user