From 0f7b62f282d88866a073656e42101307a080d0bb Mon Sep 17 00:00:00 2001 From: David Wiesen Date: Mon, 11 May 2026 09:12:50 -0700 Subject: [PATCH] Avoid loading PowerShell profiles for tool commands --- codex-rs/core/src/shell.rs | 8 ++++---- codex-rs/core/src/shell_tests.rs | 2 +- codex-rs/core/src/tools/handlers/unified_exec_tests.rs | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/codex-rs/core/src/shell.rs b/codex-rs/core/src/shell.rs index 48c760d667..e63d2289c2 100644 --- a/codex-rs/core/src/shell.rs +++ b/codex-rs/core/src/shell.rs @@ -52,10 +52,10 @@ impl Shell { } ShellType::PowerShell => { let mut args = vec![self.shell_path.to_string_lossy().to_string()]; - if !use_login_shell { - args.push("-NoProfile".to_string()); - } - + // PowerShell profiles can trigger sandbox-incompatible startup side effects, + // so keep tool execution profile-free regardless of login-shell preference. + let _ = use_login_shell; + args.push("-NoProfile".to_string()); args.push("-Command".to_string()); args.push(command.to_string()); args diff --git a/codex-rs/core/src/shell_tests.rs b/codex-rs/core/src/shell_tests.rs index f0974900b2..d3fde35ed2 100644 --- a/codex-rs/core/src/shell_tests.rs +++ b/codex-rs/core/src/shell_tests.rs @@ -142,7 +142,7 @@ fn derive_exec_args() { ); assert_eq!( test_powershell_shell.derive_exec_args("echo hello", /*use_login_shell*/ true), - vec!["pwsh.exe", "-Command", "echo hello"] + vec!["pwsh.exe", "-NoProfile", "-Command", "echo hello"] ); } diff --git a/codex-rs/core/src/tools/handlers/unified_exec_tests.rs b/codex-rs/core/src/tools/handlers/unified_exec_tests.rs index 1bdd0b82f9..a040bb68f1 100644 --- a/codex-rs/core/src/tools/handlers/unified_exec_tests.rs +++ b/codex-rs/core/src/tools/handlers/unified_exec_tests.rs @@ -105,6 +105,7 @@ fn test_get_command_respects_explicit_powershell_shell() -> anyhow::Result<()> { .map_err(anyhow::Error::msg)?; assert_eq!(command[2], "echo hello"); + assert!(command.contains(&"-NoProfile".to_string())); Ok(()) }