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:
@@ -1,4 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
use std::ffi::OsString;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -46,6 +48,7 @@ const CREDENTIAL_MASKING_FAILURE_MODE: CredentialMaskingFailureMode =
|
||||
|
||||
pub(crate) struct PreparedExecRequest {
|
||||
pub(crate) command: Vec<String>,
|
||||
native_program: Option<OsString>,
|
||||
pub(crate) cwd: AbsolutePathBuf,
|
||||
pub(crate) env: HashMap<String, String>,
|
||||
pub(crate) arg0: Option<String>,
|
||||
@@ -65,6 +68,16 @@ struct PreparedWindowsSandboxRequest {
|
||||
}
|
||||
|
||||
impl PreparedExecRequest {
|
||||
pub(crate) fn program_and_args(&self) -> Option<(&OsStr, &[String])> {
|
||||
let (program, args) = self.command.split_first()?;
|
||||
Some((
|
||||
self.native_program
|
||||
.as_deref()
|
||||
.unwrap_or_else(|| OsStr::new(program)),
|
||||
args,
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub(crate) fn credential_snapshot_proxy(&self, params: &ExecParams) -> Option<&NetworkProxy> {
|
||||
let launch = params.network_proxy.as_ref()?;
|
||||
@@ -151,6 +164,7 @@ pub(crate) async fn prepare_exec_request_with_telemetry(
|
||||
let Some(sandbox_context) = params.sandbox.as_ref() else {
|
||||
return Ok(PreparedExecRequest {
|
||||
command: params.argv.clone(),
|
||||
native_program: None,
|
||||
cwd: native_path(¶ms.cwd, "cwd")?,
|
||||
env,
|
||||
arg0: params.arg0.clone(),
|
||||
@@ -300,6 +314,7 @@ pub(crate) async fn prepare_exec_request_with_telemetry(
|
||||
};
|
||||
Ok(PreparedExecRequest {
|
||||
command: request.command,
|
||||
native_program: request.native_program,
|
||||
cwd: native_path(&request.cwd, "cwd")?,
|
||||
env: request.env,
|
||||
arg0: request.arg0,
|
||||
|
||||
Reference in New Issue
Block a user