Fix Windows sandbox helper launch path

This commit is contained in:
David Wiesen
2026-06-05 09:12:24 -07:00
parent e5af672d73
commit ca34323c46
2 changed files with 29 additions and 18 deletions
@@ -22,18 +22,30 @@ pub(crate) const RESOURCES_DIRNAME: &str = "codex-resources";
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub(crate) enum HelperExecutable {
CommandRunner,
Setup,
}
impl HelperExecutable {
fn file_name(self) -> &'static str {
match self {
Self::CommandRunner => "codex-command-runner.exe",
Self::Setup => "codex-windows-sandbox-setup.exe",
}
}
fn label(self) -> &'static str {
match self {
Self::CommandRunner => "command-runner",
Self::Setup => "setup-helper",
}
}
fn materialized_stem(self) -> &'static str {
match self {
Self::CommandRunner => "codex-command-runner",
// Avoid persisting the "setup" spelling into user-writable runtime paths because
// Windows UAC installer detection can misclassify it there.
Self::Setup => "codex-sandbox-helper",
}
}
}
@@ -218,18 +230,13 @@ fn helper_destination_for_source(
}
fn materialized_file_name(kind: HelperExecutable, suffix: &str) -> String {
let source_name = kind.file_name();
let path = Path::new(source_name);
let stem = path
.file_stem()
.and_then(|stem| stem.to_str())
.unwrap_or(source_name);
let path = Path::new(kind.file_name());
let extension = path
.extension()
.and_then(|ext| ext.to_str())
.map(|ext| format!(".{ext}"))
.unwrap_or_default();
format!("{stem}-{suffix}{extension}")
format!("{}-{suffix}{extension}", kind.materialized_stem())
}
fn helper_version_suffix(source: &Path) -> Result<String> {
@@ -559,4 +566,11 @@ mod tests {
assert_eq!(file_name, "codex-command-runner-test-suffix.exe");
}
#[test]
fn setup_helper_materialization_uses_neutral_file_name() {
let file_name = materialized_file_name(HelperExecutable::Setup, "test-suffix");
assert_eq!(file_name, "codex-sandbox-helper-test-suffix.exe");
}
}
+8 -11
View File
@@ -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::identity::sandbox_setup_is_complete;
use crate::logging::current_log_file_path;
use crate::logging::log_note;
@@ -209,8 +211,8 @@ fn run_setup_refresh_inner(
};
let json = serde_json::to_vec(&payload)?;
let b64 = BASE64_STANDARD.encode(json);
let exe = find_setup_exe();
let sbx_dir = sandbox_dir(request.codex_home);
let exe = resolve_setup_exe_for_launch(request.codex_home, &sbx_dir);
let log_path = current_log_file_path(&sbx_dir);
let cleared_report = match clear_setup_error_report(request.codex_home) {
Ok(()) => true,
@@ -662,19 +664,14 @@ fn quote_arg(arg: &str) -> String {
out
}
fn find_setup_exe() -> PathBuf {
if let Ok(exe) = std::env::current_exe()
&& let Some(setup_exe) = find_setup_exe_for_current_exe(&exe)
{
return setup_exe;
}
PathBuf::from(SETUP_EXE_FILENAME)
}
fn find_setup_exe_for_current_exe(exe: &Path) -> Option<PathBuf> {
bundled_executable_path_for_exe(exe, SETUP_EXE_FILENAME)
}
fn resolve_setup_exe_for_launch(codex_home: &Path, sbx_dir: &Path) -> PathBuf {
resolve_helper_for_launch(HelperExecutable::Setup, codex_home, Some(sbx_dir))
}
fn report_helper_failure(
codex_home: &Path,
cleared_report: bool,
@@ -716,7 +713,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 = resolve_setup_exe_for_launch(codex_home, &sandbox_dir(codex_home));
let payload_json = serde_json::to_string(payload).map_err(|err| {
failure(
SetupErrorCode::OrchestratorPayloadSerializeFailed,