diff --git a/codex-rs/core/src/shell_snapshot.rs b/codex-rs/core/src/shell_snapshot.rs index 40cb4a9605..2b35f0b549 100644 --- a/codex-rs/core/src/shell_snapshot.rs +++ b/codex-rs/core/src/shell_snapshot.rs @@ -186,7 +186,7 @@ async fn write_shell_snapshot( output_path: &AbsolutePathBuf, cwd: &AbsolutePathBuf, ) -> Result<()> { - if shell_type == ShellType::PowerShell || shell_type == ShellType::Cmd { + if shell_type == ShellType::Cmd { bail!("Shell snapshot not supported yet for {shell_type:?}"); } let shell = get_shell(shell_type.clone(), /*path*/ None) @@ -235,8 +235,14 @@ async fn validate_snapshot( snapshot_path: &AbsolutePathBuf, cwd: &AbsolutePathBuf, ) -> Result<()> { - let snapshot_path_display = snapshot_path.display(); - let script = format!("set -e; . \"{snapshot_path_display}\""); + let snapshot_path_display = snapshot_path.display().to_string(); + let script = match shell.shell_type { + ShellType::PowerShell => { + let snapshot_path = snapshot_path_display.replace('\'', "''"); + format!(". '{snapshot_path}'") + } + _ => format!("set -e; . \"{snapshot_path_display}\""), + }; run_script_with_timeout( shell, &script, diff --git a/codex-rs/core/src/tools/runtimes/mod.rs b/codex-rs/core/src/tools/runtimes/mod.rs index 073fda8ec4..0d2d3b7fea 100644 --- a/codex-rs/core/src/tools/runtimes/mod.rs +++ b/codex-rs/core/src/tools/runtimes/mod.rs @@ -8,6 +8,7 @@ use crate::exec_env::CODEX_THREAD_ID_ENV_VAR; use crate::path_utils; use crate::sandboxing::SandboxPermissions; use crate::shell::Shell; +use crate::shell::ShellType; use crate::tools::sandboxing::ToolError; #[cfg(target_os = "macos")] use codex_network_proxy::CODEX_PROXY_GIT_SSH_COMMAND_MARKER; @@ -67,18 +68,20 @@ pub(crate) fn exec_env_for_sandbox_permissions( env } -/// POSIX-only helper: for commands produced by `Shell::derive_exec_args` -/// for Bash/Zsh/sh of the form `[shell_path, "-lc", "