diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 056e05e1a9..6e2fdffd03 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -757,7 +757,9 @@ version = "0.0.0" dependencies = [ "anyhow", "clap", + "codex-common", "codex-core", + "dotenvy", "landlock", "libc", "seccompiler", diff --git a/codex-rs/linux-sandbox/Cargo.toml b/codex-rs/linux-sandbox/Cargo.toml index c8cd1078c0..3120a5c72f 100644 --- a/codex-rs/linux-sandbox/Cargo.toml +++ b/codex-rs/linux-sandbox/Cargo.toml @@ -18,6 +18,8 @@ workspace = true anyhow = "1" clap = { version = "4", features = ["derive"] } codex-core = { path = "../core" } +codex-common = { path = "../common", features = ["cli"] } +dotenvy = "0.15.7" tokio = { version = "1", features = ["rt-multi-thread"] } [dev-dependencies] diff --git a/codex-rs/linux-sandbox/src/lib.rs b/codex-rs/linux-sandbox/src/lib.rs index 568f015822..960678467c 100644 --- a/codex-rs/linux-sandbox/src/lib.rs +++ b/codex-rs/linux-sandbox/src/lib.rs @@ -43,6 +43,10 @@ where crate::run_main(); } + // This modifies the environment, which is not thread-safe, so do this + // before creating any threads/the Tokio runtime. + load_dotenv(); + // Regular invocation – create a Tokio runtime and execute the provided // async entry-point. let runtime = tokio::runtime::Runtime::new()?; @@ -61,3 +65,11 @@ where pub fn run_main() -> ! { panic!("codex-linux-sandbox is only supported on Linux"); } + +/// Load env vars from ~/.codex/.env and `$(pwd)/.env`. +fn load_dotenv() { + if let Ok(codex_home) = codex_core::config::find_codex_home() { + dotenvy::from_path(codex_home.join(".env")).ok(); + } + dotenvy::dotenv().ok(); +}