Add Windows sandbox unified exec runtime support (#15578)

## Summary

This is the runtime/foundation half of the Windows sandbox unified-exec
work.

- add Windows sandbox `unified_exec` session support in
`windows-sandbox-rs` for both:
  - the legacy restricted-token backend
  - the elevated runner backend
- extend the PTY/process runtime so driver-backed sessions can support:
  - stdin streaming
  - stdout/stderr separation
  - exit propagation
  - PTY resize hooks
- add Windows sandbox runtime coverage in `codex-windows-sandbox` /
`codex-utils-pty`

This PR does **not** enable Windows sandbox `UnifiedExec` for product
callers yet because hooking this up to app-server comes in the next PR.

Windows sandbox advertising is intentionally kept aligned with `main`,
so sandboxed Windows callers still fall back to `ShellCommand`.

This PR isolates the runtime/session layer so it can be reviewed
independently from product-surface enablement.

---------

Co-authored-by: jif-oai <jif@openai.com>
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
authored and GitHub committed 2026-04-21 10:44:49 -07:00
1 parent 38ba876ea9
commit 8612714aa6
32 files changed
+2620 -210

No files matched your search

@@ -64,6 +64,15 @@ pub fn quote_windows_arg(arg: &str) -> String {
quoted
}
/// Build a Windows command line for CreateProcess-style APIs.
#[cfg(target_os = "windows")]
pub fn argv_to_command_line(argv: &[String]) -> String {
argv.iter()
.map(|arg| quote_windows_arg(arg))
.collect::<Vec<_>>()
.join(" ")
}
// Produce a readable description for a Win32 error code.
pub fn format_last_error(err: i32) -> String {
unsafe {
@@ -190,3 +199,38 @@ fn sid_bytes_from_string(sid_str: &str) -> Result<Vec<u8>> {
}
Ok(out)
}
#[cfg(test)]
mod tests {
use super::argv_to_command_line;
use pretty_assertions::assert_eq;
#[test]
fn argv_to_command_line_quotes_each_argument_independently() {
let argv = vec![
"cmd.exe".to_string(),
"/c".to_string(),
"\"C:\\Program Files\\PowerShell\\7\\pwsh.exe\" -NoProfile -EncodedCommand abc=="
.to_string(),
];
assert_eq!(
argv_to_command_line(&argv),
"cmd.exe /c \"\\\"C:\\Program Files\\PowerShell\\7\\pwsh.exe\\\" -NoProfile -EncodedCommand abc==\""
);
}
#[test]
fn argv_to_command_line_quotes_regular_program_args() {
let argv = vec![
"pwsh.exe".to_string(),
"-Command".to_string(),
"Write-Output \"hello world\"".to_string(),
];
assert_eq!(
argv_to_command_line(&argv),
"pwsh.exe -Command \"Write-Output \\\"hello world\\\"\""
);
}
}