Preserve native sandbox executable paths and PTY dispatch names (#61910)

## Why

Sandbox helpers with non-UTF-8 paths can lose their exact executable path when converted into command requests. PTY launches with a custom `argv[0]` can also try to execute the dispatch name instead of the configured program.

## What changed

- Carry native executable paths through sandbox requests, local execution, shell snapshots, and sandbox integrity checks.
- Use native Unix PTY spawning when `argv[0]` differs from the executable, preserving the dispatch name and controlling terminal setup.
- Preserve PTY executable lookup through the child environment's `PATH` and fallback to its home directory when the requested working directory is missing.

## Testing

Add regression coverage for non-UTF-8 sandbox helper paths, PTY dispatch names, child `HOME`/`PATH` lookup, controlling terminals, and exit-code preservation.

GitOrigin-RevId: 6a2af0486220d98195f5d67fde2597e3c4515e11
This commit is contained in:
viyatb-oai
2026-11-16 23:26:42 +00:00
committed by copyberry
parent cff061fca9
commit c9df641eac
30 changed files with 346 additions and 108 deletions
+12 -19
View File
@@ -228,17 +228,11 @@ impl CommandExecManager {
return Ok(());
}
let ExecRequest {
command,
cwd,
env,
expiration,
sandbox: _sandbox,
arg0,
..
} = exec_request;
let env = &exec_request.env;
let arg0 = &exec_request.arg0;
// TODO(anp): Keep PathUri through the local command launch boundary.
let cwd = cwd
let cwd = exec_request
.cwd
.to_abs_path()
.map_err(|err| invalid_request(format!("invalid command cwd: {err}")))?;
@@ -251,8 +245,8 @@ impl CommandExecManager {
};
let sessions = Arc::clone(&self.sessions);
let (program, args) = command
.split_first()
let (program, args) = exec_request
.program_and_args()
.ok_or_else(|| invalid_request("command must not be empty"))?;
{
let mut sessions = self.sessions.lock().await;
@@ -272,22 +266,21 @@ impl CommandExecManager {
program,
args,
cwd.as_path(),
&env,
&arg0,
env,
arg0,
size.unwrap_or_default(),
codex_utils_pty::ChildFds::Inherited(&[]),
)
.await
} else if stream_stdin {
codex_utils_pty::spawn_pipe_process(program, args, cwd.as_path(), &env, &arg0, &[])
.await
codex_utils_pty::spawn_pipe_process(program, args, cwd.as_path(), env, arg0, &[]).await
} else {
codex_utils_pty::spawn_pipe_process_no_stdin(
program,
args,
cwd.as_path(),
&env,
&arg0,
env,
arg0,
&[],
)
.await
@@ -309,7 +302,7 @@ impl CommandExecManager {
control_rx,
stream_stdin,
stream_stdout_stderr,
expiration,
expiration: exec_request.expiration,
output_bytes_cap,
})
.await;