From a0432ed336d3bc27648b6ea206543de92904e8d7 Mon Sep 17 00:00:00 2001 From: David Wiesen Date: Tue, 2 Jun 2026 10:36:19 -0700 Subject: [PATCH] Fix Windows sandbox setup helper resolution --- .../src/helper_materialization.rs | 10 ++++++++++ codex-rs/windows-sandbox-rs/src/setup.rs | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/codex-rs/windows-sandbox-rs/src/helper_materialization.rs b/codex-rs/windows-sandbox-rs/src/helper_materialization.rs index e5b202dede..3fb10269ce 100644 --- a/codex-rs/windows-sandbox-rs/src/helper_materialization.rs +++ b/codex-rs/windows-sandbox-rs/src/helper_materialization.rs @@ -22,18 +22,21 @@ pub(crate) const RESOURCES_DIRNAME: &str = "codex-resources"; #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub(crate) enum HelperExecutable { CommandRunner, + SetupHelper, } impl HelperExecutable { fn file_name(self) -> &'static str { match self { Self::CommandRunner => "codex-command-runner.exe", + Self::SetupHelper => "codex-windows-sandbox-setup.exe", } } fn label(self) -> &'static str { match self { Self::CommandRunner => "command-runner", + Self::SetupHelper => "setup-helper", } } } @@ -559,4 +562,11 @@ mod tests { assert_eq!(file_name, "codex-command-runner-test-suffix.exe"); } + + #[test] + fn materialized_setup_helper_name_adds_suffix_before_extension() { + let file_name = materialized_file_name(HelperExecutable::SetupHelper, "test-suffix"); + + assert_eq!(file_name, "codex-windows-sandbox-setup-test-suffix.exe"); + } } diff --git a/codex-rs/windows-sandbox-rs/src/setup.rs b/codex-rs/windows-sandbox-rs/src/setup.rs index a0f46fe3f8..fbbd406d98 100644 --- a/codex-rs/windows-sandbox-rs/src/setup.rs +++ b/codex-rs/windows-sandbox-rs/src/setup.rs @@ -12,8 +12,10 @@ use std::process::Stdio; use crate::allow::AllowDenyPaths; use crate::allow::compute_allow_paths_for_permissions; +use crate::helper_materialization::HelperExecutable; use crate::helper_materialization::bundled_executable_path_for_exe; use crate::helper_materialization::helper_bin_dir; +use crate::helper_materialization::resolve_helper_for_launch; use crate::logging::log_note; use crate::path_normalization::canonical_path_key; use crate::path_normalization::canonicalize_path; @@ -208,7 +210,7 @@ fn run_setup_refresh_inner( }; let json = serde_json::to_vec(&payload)?; let b64 = BASE64_STANDARD.encode(json); - let exe = find_setup_exe(); + let exe = find_setup_exe(request.codex_home); // Refresh should never request elevation; ensure verb isn't set and we don't trigger UAC. let mut cmd = Command::new(&exe); cmd.arg(&b64).stdout(Stdio::null()).stderr(Stdio::null()); @@ -639,7 +641,17 @@ fn quote_arg(arg: &str) -> String { out } -fn find_setup_exe() -> PathBuf { +fn find_setup_exe(codex_home: &Path) -> PathBuf { + let sandbox_log_dir = sandbox_dir(codex_home); + let copied = resolve_helper_for_launch( + HelperExecutable::SetupHelper, + codex_home, + Some(&sandbox_log_dir), + ); + if copied.exists() { + return copied; + } + if let Ok(exe) = std::env::current_exe() && let Some(setup_exe) = find_setup_exe_for_current_exe(&exe) { @@ -682,7 +694,7 @@ fn run_setup_exe( use windows_sys::Win32::UI::Shell::SEE_MASK_NOCLOSEPROCESS; use windows_sys::Win32::UI::Shell::SHELLEXECUTEINFOW; use windows_sys::Win32::UI::Shell::ShellExecuteExW; - let exe = find_setup_exe(); + let exe = find_setup_exe(codex_home); let payload_json = serde_json::to_string(payload).map_err(|err| { failure( SetupErrorCode::OrchestratorPayloadSerializeFailed,