mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user