mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
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:
32 files changed
+2620
-210
No files matched your search
@@ -3,6 +3,7 @@ use std::path::Path;
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::ProcessDriver;
|
||||
use crate::SpawnedProcess;
|
||||
use crate::TerminalSize;
|
||||
use crate::combine_output_receivers;
|
||||
@@ -10,6 +11,7 @@ use crate::combine_output_receivers;
|
||||
use crate::pipe::spawn_process_no_stdin_with_inherited_fds;
|
||||
#[cfg(unix)]
|
||||
use crate::pty::spawn_process_with_inherited_fds;
|
||||
use crate::spawn_from_driver;
|
||||
use crate::spawn_pipe_process;
|
||||
use crate::spawn_pipe_process_no_stdin;
|
||||
use crate::spawn_pty_process;
|
||||
@@ -589,6 +591,103 @@ async fn pipe_process_can_expose_split_stdout_and_stderr() -> anyhow::Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn driver_backed_process_can_expose_split_stdout_and_stderr() -> anyhow::Result<()> {
|
||||
let (writer_tx, _writer_rx) = tokio::sync::mpsc::channel::<Vec<u8>>(1);
|
||||
let (stdout_tx, stdout_driver_rx) = tokio::sync::broadcast::channel::<Vec<u8>>(8);
|
||||
let (stderr_tx, stderr_driver_rx) = tokio::sync::broadcast::channel::<Vec<u8>>(8);
|
||||
let (exit_tx, exit_rx) = tokio::sync::oneshot::channel::<i32>();
|
||||
|
||||
let spawned = spawn_from_driver(ProcessDriver {
|
||||
writer_tx,
|
||||
stdout_rx: stdout_driver_rx,
|
||||
stderr_rx: Some(stderr_driver_rx),
|
||||
exit_rx,
|
||||
terminator: None,
|
||||
writer_handle: None,
|
||||
resizer: None,
|
||||
});
|
||||
|
||||
let SpawnedProcess {
|
||||
session: _session,
|
||||
stdout_rx,
|
||||
stderr_rx,
|
||||
exit_rx,
|
||||
} = spawned;
|
||||
let stdout_task = tokio::spawn(async move { collect_split_output(stdout_rx).await });
|
||||
let stderr_task = tokio::spawn(async move { collect_split_output(stderr_rx).await });
|
||||
|
||||
stdout_tx.send(b"driver-out".to_vec())?;
|
||||
stderr_tx.send(b"driver-err".to_vec())?;
|
||||
drop(stdout_tx);
|
||||
drop(stderr_tx);
|
||||
exit_tx.send(0).expect("send exit code");
|
||||
|
||||
let timeout = tokio::time::Duration::from_secs(2);
|
||||
let code = tokio::time::timeout(timeout, exit_rx)
|
||||
.await
|
||||
.map_err(|_| anyhow::anyhow!("timed out waiting for driver exit"))?
|
||||
.unwrap_or(-1);
|
||||
let stdout = tokio::time::timeout(timeout, stdout_task)
|
||||
.await
|
||||
.map_err(|_| anyhow::anyhow!("timed out waiting to drain driver stdout"))??;
|
||||
let stderr = tokio::time::timeout(timeout, stderr_task)
|
||||
.await
|
||||
.map_err(|_| anyhow::anyhow!("timed out waiting to drain driver stderr"))??;
|
||||
|
||||
assert_eq!(stdout, b"driver-out".to_vec());
|
||||
assert_eq!(stderr, b"driver-err".to_vec());
|
||||
assert_eq!(code, 0);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn driver_backed_process_can_resize_via_resizer_hook() -> anyhow::Result<()> {
|
||||
let (writer_tx, _writer_rx) = tokio::sync::mpsc::channel::<Vec<u8>>(1);
|
||||
let (_stdout_tx, stdout_driver_rx) = tokio::sync::broadcast::channel::<Vec<u8>>(8);
|
||||
let (exit_tx, exit_rx) = tokio::sync::oneshot::channel::<i32>();
|
||||
let (size_tx, size_rx) = tokio::sync::oneshot::channel::<TerminalSize>();
|
||||
|
||||
let size_tx = std::sync::Arc::new(std::sync::Mutex::new(Some(size_tx)));
|
||||
let spawned = spawn_from_driver(ProcessDriver {
|
||||
writer_tx,
|
||||
stdout_rx: stdout_driver_rx,
|
||||
stderr_rx: None,
|
||||
exit_rx,
|
||||
terminator: None,
|
||||
writer_handle: None,
|
||||
resizer: Some(Box::new(move |size| {
|
||||
if let Ok(mut guard) = size_tx.lock()
|
||||
&& let Some(size_tx) = guard.take()
|
||||
{
|
||||
let _ = size_tx.send(size);
|
||||
}
|
||||
Ok(())
|
||||
})),
|
||||
});
|
||||
|
||||
spawned.session.resize(TerminalSize {
|
||||
rows: 40,
|
||||
cols: 120,
|
||||
})?;
|
||||
exit_tx.send(0).expect("send exit code");
|
||||
|
||||
let resized = tokio::time::timeout(tokio::time::Duration::from_secs(2), size_rx)
|
||||
.await
|
||||
.map_err(|_| anyhow::anyhow!("timed out waiting for resize"))?
|
||||
.expect("receive resized terminal size");
|
||||
assert_eq!(
|
||||
resized,
|
||||
TerminalSize {
|
||||
rows: 40,
|
||||
cols: 120
|
||||
}
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn pipe_terminate_aborts_detached_readers() -> anyhow::Result<()> {
|
||||
if !setsid_available() {
|
||||
|
||||
Reference in new issue
Block a user