sandboxing: use OsString for SandboxCommand.program (#15897)

## Why

`SandboxCommand.program` represents an executable path, but keeping it
as `String` forced path-backed callers to run `to_string_lossy()` before
the sandbox layer ever touched the command. That loses fidelity earlier
than necessary and adds avoidable conversions in runtimes that already
have a `PathBuf`.

## What changed

- Changed `SandboxCommand.program` to `OsString`.
- Updated `SandboxManager::transform` to keep the program and argv in
`OsString` form until the `SandboxExecRequest` conversion boundary.
- Switched the path-backed `apply_patch` and `js_repl` runtimes to pass
`into_os_string()` instead of `to_string_lossy()`.
- Updated the remaining string-backed builders and tests to match the
new type while preserving the existing Linux helper `arg0` behavior.

## Verification

- `cargo test -p codex-sandboxing`
- `just argument-comment-lint -p codex-core -p codex-sandboxing`
- `cargo test -p codex-core` currently fails in unrelated existing
config tests: `config::tests::approvals_reviewer_*` and
`config::tests::smart_approvals_alias_*`
This commit is contained in:
Michael Bolin
2026-03-26 20:38:33 +00:00
committed by GitHub
parent b23789b770
commit dfb36573cd
8 changed files with 33 additions and 24 deletions
+1 -1
View File
@@ -272,7 +272,7 @@ pub fn build_exec_request(
let manager = SandboxManager::new();
let command = SandboxCommand {
program: program.clone(),
program: program.clone().into(),
args: args.to_vec(),
cwd,
env,
+1 -1
View File
@@ -1045,7 +1045,7 @@ impl JsReplManager {
has_managed_network_requirements,
);
let command = SandboxCommand {
program: node_path.to_string_lossy().to_string(),
program: node_path.into_os_string(),
args: vec![
"--experimental-vm-modules".to_string(),
kernel_path.to_string_lossy().to_string(),
@@ -97,7 +97,7 @@ impl ApplyPatchRuntime {
fn build_sandbox_command_with_program(req: &ApplyPatchRequest, exe: PathBuf) -> SandboxCommand {
SandboxCommand {
program: exe.to_string_lossy().to_string(),
program: exe.into_os_string(),
args: vec![
CODEX_CORE_APPLY_PATCH_ARG1.to_string(),
req.action.patch.clone(),
@@ -98,10 +98,7 @@ fn build_sandbox_command_prefers_configured_codex_self_exe_for_apply_patch() {
let command = ApplyPatchRuntime::build_sandbox_command(&request, Some(&codex_self_exe))
.expect("build sandbox command");
assert_eq!(
command.program,
codex_self_exe.to_string_lossy().to_string()
);
assert_eq!(command.program, codex_self_exe.into_os_string());
}
#[cfg(not(target_os = "windows"))]
@@ -136,7 +133,6 @@ fn build_sandbox_command_falls_back_to_current_exe_for_apply_patch() {
command.program,
std::env::current_exe()
.expect("current exe")
.to_string_lossy()
.to_string()
.into_os_string()
);
}
+1 -1
View File
@@ -28,7 +28,7 @@ pub(crate) fn build_sandbox_command(
.split_first()
.ok_or_else(|| ToolError::Rejected("command args are empty".to_string()))?;
Ok(SandboxCommand {
program: program.clone(),
program: program.clone().into(),
args: args.to_vec(),
cwd: cwd.to_path_buf(),
env: env.clone(),
@@ -864,7 +864,7 @@ impl CoreShellCommandExecutor {
self.network.is_some(),
);
let command = SandboxCommand {
program: program.clone(),
program: program.clone().into(),
args: args.to_vec(),
cwd: workdir.to_path_buf(),
env,