Files
codex/codex-rs/exec-server/src/sandbox_integrity/dependencies.rs
T
viyatb-oai c656014177 Centralize exec-server launches in WrappedSandboxCommand (#61942)
## What changed

- Move process spawning and Windows token session preparation into `codex-sandboxing`. Keep filesystem overrides, proxy enforcement, and the restricting SID with the prepared command, and reject conversion to a plain command request when a Windows session launcher is required.
- Route shell snapshot capture and replay through the prepared command. Limit script replacement to the submitted shell invocation while preserving its sandbox, environment, and proxy.
- Pass borrowed launch facts to sandbox integrity checks, and distinguish explicitly supplied runtime readable paths from automatic proxy CA bundle discovery.

## Testing

Extend coverage for Windows TEMP permissions and managed proxy routing with empty workspace roots, native launch and prewarm input validation, and proxy availability after the process leader exits while a descendant holds stdout open.

GitOrigin-RevId: fe2bdb9e44f4fb273295fbde66b44bf01f0b7fbc
2026-11-17 02:02:21 +00:00

70 lines
2.2 KiB
Rust

//! Shared inventory entries and filesystem facts, independent of any checker.
use codex_sandboxing::SandboxIntegrityRequest;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
#[cfg(not(target_os = "macos"))]
use std::collections::HashMap;
#[cfg(not(target_os = "macos"))]
use std::ffi::OsString;
use std::fs;
use std::io;
use std::path::PathBuf;
pub(super) type Dependency = (&'static str, io::Result<PathBuf>);
/// Inputs retained by the blocking worker. Seatbelt checks fixed paths and uses only the policy cwd.
pub(super) struct IntegrityCommand {
pub(super) sandbox_policy_cwd: PathUri,
#[cfg(not(target_os = "macos"))]
pub(super) cwd: PathUri,
#[cfg(not(target_os = "macos"))]
pub(super) launcher: Option<OsString>,
#[cfg(not(target_os = "macos"))]
pub(super) env: HashMap<String, String>,
}
impl From<SandboxIntegrityRequest<'_>> for IntegrityCommand {
fn from(request: SandboxIntegrityRequest<'_>) -> Self {
Self {
sandbox_policy_cwd: request.sandbox_policy_cwd.clone(),
#[cfg(not(target_os = "macos"))]
cwd: request.cwd.clone(),
#[cfg(not(target_os = "macos"))]
launcher: request.launcher.map(OsString::from),
#[cfg(not(target_os = "macos"))]
env: request.env.clone(),
}
}
}
pub(super) struct DependencyTarget {
pub path: AbsolutePathBuf,
pub metadata: fs::Metadata,
pub resolved_path: Option<AbsolutePathBuf>,
}
impl DependencyTarget {
pub(super) fn inspect(path: io::Result<PathBuf>) -> io::Result<Self> {
let path = AbsolutePathBuf::from_absolute_path(path?)?;
Ok(Self {
metadata: fs::metadata(&path)?,
resolved_path: path.canonicalize().ok(),
path,
})
}
}
pub(super) fn codex_executable() -> Dependency {
("codex", std::env::current_exe())
}
#[cfg(any(target_os = "linux", target_os = "windows"))]
pub(super) fn codex_and_launcher_dependencies(request: &IntegrityCommand) -> Vec<Dependency> {
let mut dependencies = vec![codex_executable()];
if let Some(exe) = request.launcher.as_deref() {
dependencies.push(("sandbox_launcher", Ok(PathBuf::from(exe))));
}
dependencies
}