fix(linux-sandbox): scope nested proxy fallback to codex bwrap

This commit is contained in:
viyatb-oai
2026-02-23 13:00:50 -08:00
parent 7e3a04cabb
commit f9eac137e5
2 changed files with 50 additions and 1 deletions
+24 -1
View File
@@ -201,7 +201,7 @@ fn has_bwrap_ancestor() -> bool {
if pid == 0 {
return false;
}
if process_comm(pid).as_deref() == Some("bwrap") {
if is_codex_bwrap_process(pid) {
return true;
}
pid = match parent_pid_of(pid) {
@@ -213,6 +213,23 @@ fn has_bwrap_ancestor() -> bool {
false
}
fn is_codex_bwrap_process(pid: u32) -> bool {
if process_comm(pid).as_deref() != Some("bwrap") {
return false;
}
let cmdline = match process_cmdline(pid) {
Some(cmdline) => cmdline,
None => return false,
};
is_codex_bwrap_cmdline(cmdline.as_slice())
}
fn is_codex_bwrap_cmdline(cmdline: &[String]) -> bool {
cmdline
.windows(2)
.any(|pair| pair[0] == "--argv0" && pair[1] == "codex-linux-sandbox")
}
fn process_comm(pid: u32) -> Option<String> {
let pid = i32::try_from(pid).ok()?;
let process = Process::new(pid).ok()?;
@@ -220,6 +237,12 @@ fn process_comm(pid: u32) -> Option<String> {
Some(stat.comm)
}
fn process_cmdline(pid: u32) -> Option<Vec<String>> {
let pid = i32::try_from(pid).ok()?;
let process = Process::new(pid).ok()?;
process.cmdline().ok()
}
fn parent_pid_of(pid: u32) -> Option<u32> {
let pid = i32::try_from(pid).ok()?;
let process = Process::new(pid).ok()?;
@@ -157,3 +157,29 @@ fn valid_inner_stage_modes_do_not_panic() {
ensure_inner_stage_mode_is_valid(false, true);
ensure_inner_stage_mode_is_valid(true, true);
}
#[test]
fn codex_bwrap_cmdline_requires_argv0_marker() {
assert_eq!(
is_codex_bwrap_cmdline(&[
"bwrap".to_string(),
"--argv0".to_string(),
"codex-linux-sandbox".to_string(),
"--".to_string(),
"/path/to/codex-linux-sandbox".to_string(),
]),
true
);
assert_eq!(
is_codex_bwrap_cmdline(&["bwrap".to_string(), "--".to_string(), "/bin/sh".to_string(),]),
false
);
assert_eq!(
is_codex_bwrap_cmdline(&[
"bwrap".to_string(),
"--argv0".to_string(),
"bash".to_string(),
]),
false
);
}