mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
## Why Private desktops owned by short-lived sandbox wrappers disappear when those wrappers exit, preventing reuse across filesystem helper requests. ## What changed - Select and cache private desktops in the calling process, keeping desktops separate for different sandbox permissions. - Pass the desktop name through the wrapper to the restricted-token and elevated backends so helpers reuse the selected desktop. - Separate sandbox account preparation from filesystem ACL refresh so desktop selection does not perform the wrapper's refresh. - Propagate desktop preparation errors and require a desktop name when the wrapper's private desktop flag is set. ## Testing Add a Windows filesystem regression test covering desktop survival and reuse across reads, writes, metadata queries, and streaming reads, plus separate read-only permissions and rejected writes. Extend wrapper argument tests to cover named desktops and rejection of a missing desktop name. GitOrigin-RevId: 05a1cb829a902732248bfa7f4ad7470d911fa9f6
197 lines
6.7 KiB
Rust
197 lines
6.7 KiB
Rust
//! Unified exec session spawner for Windows sandboxing.
|
|
//!
|
|
//! This module is the thin orchestration layer for Windows unified-exec sessions.
|
|
//! Backend-specific mechanics live in sibling modules:
|
|
//! - `backends::legacy` adapts the direct restricted-token spawn path into a live session.
|
|
//! - `backends::elevated` adapts the elevated command-runner IPC path into the same session API.
|
|
//! - `backends::windows_common` holds the small shared Windows backend helpers
|
|
//! used by both.
|
|
|
|
mod backends;
|
|
|
|
use anyhow::Result;
|
|
use anyhow::bail;
|
|
use codex_protocol::config_types::WindowsSandboxLevel;
|
|
use codex_protocol::models::PermissionProfile;
|
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
|
use codex_utils_pty::SpawnedProcess;
|
|
use std::collections::HashMap;
|
|
use std::path::Path;
|
|
use std::path::PathBuf;
|
|
|
|
/// Fully resolved Windows sandbox session launch request.
|
|
///
|
|
/// Callers should parse their own input shape first, then use this request to
|
|
/// share the elevated-vs-legacy backend selection and session launch path.
|
|
// TODO(anp): Reconcile Windows backend and desktop copies with the supplied sandbox
|
|
// context (TurnEnvironment::sandbox_context for turns), preserving this launch snapshot.
|
|
pub struct WindowsSandboxSessionRequest<'a> {
|
|
pub permission_profile: &'a PermissionProfile,
|
|
pub workspace_roots: &'a [AbsolutePathBuf],
|
|
pub codex_home: &'a Path,
|
|
pub command: Vec<String>,
|
|
pub cwd: &'a Path,
|
|
pub env_map: HashMap<String, String>,
|
|
pub windows_sandbox_level: WindowsSandboxLevel,
|
|
pub proxy_enforced: bool,
|
|
pub network_proxy_restricting_sid: Option<String>,
|
|
pub proxy_settings_mode: crate::WindowsSandboxProxySettingsMode,
|
|
pub timeout_ms: Option<u64>,
|
|
pub read_roots_override: Option<&'a [PathBuf]>,
|
|
pub read_roots_include_platform_defaults: bool,
|
|
pub write_roots_override: Option<&'a [PathBuf]>,
|
|
pub deny_read_paths_override: &'a [AbsolutePathBuf],
|
|
pub deny_write_paths_override: &'a [AbsolutePathBuf],
|
|
pub tty: bool,
|
|
pub stdin_open: bool,
|
|
pub use_private_desktop: bool,
|
|
}
|
|
|
|
pub async fn spawn_windows_sandbox_session_for_level(
|
|
request: WindowsSandboxSessionRequest<'_>,
|
|
) -> Result<SpawnedProcess> {
|
|
spawn_windows_sandbox_session_with_desktop(request, /*private_desktop_name*/ None).await
|
|
}
|
|
|
|
pub(crate) async fn spawn_windows_sandbox_session_with_desktop(
|
|
request: WindowsSandboxSessionRequest<'_>,
|
|
private_desktop_name: Option<String>,
|
|
) -> Result<SpawnedProcess> {
|
|
if matches!(request.windows_sandbox_level, WindowsSandboxLevel::Elevated) {
|
|
backends::elevated::spawn_windows_sandbox_session_elevated_for_permission_profile(
|
|
request.permission_profile,
|
|
request.workspace_roots,
|
|
request.codex_home,
|
|
request.command,
|
|
request.cwd,
|
|
request.env_map,
|
|
request.proxy_enforced,
|
|
request.network_proxy_restricting_sid,
|
|
request.proxy_settings_mode,
|
|
request.timeout_ms,
|
|
request.read_roots_override,
|
|
request.read_roots_include_platform_defaults,
|
|
request.write_roots_override,
|
|
request.deny_read_paths_override,
|
|
request.deny_write_paths_override,
|
|
request.tty,
|
|
request.stdin_open,
|
|
request.use_private_desktop,
|
|
private_desktop_name,
|
|
)
|
|
.await
|
|
} else {
|
|
if request.proxy_enforced {
|
|
bail!("managed networking requires the elevated Windows sandbox backend");
|
|
}
|
|
if request.network_proxy_restricting_sid.is_some() {
|
|
bail!("network proxy restricting SID requires the elevated Windows sandbox backend");
|
|
}
|
|
backends::legacy::spawn_windows_sandbox_session_legacy(
|
|
request.permission_profile,
|
|
request.workspace_roots,
|
|
request.codex_home,
|
|
request.command,
|
|
request.cwd,
|
|
request.env_map,
|
|
request.timeout_ms,
|
|
request.deny_read_paths_override,
|
|
request.deny_write_paths_override,
|
|
request.tty,
|
|
request.stdin_open,
|
|
request.use_private_desktop,
|
|
private_desktop_name,
|
|
)
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub async fn spawn_windows_sandbox_session_legacy(
|
|
permission_profile: &PermissionProfile,
|
|
workspace_roots: &[AbsolutePathBuf],
|
|
codex_home: &Path,
|
|
command: Vec<String>,
|
|
cwd: &Path,
|
|
env_map: HashMap<String, String>,
|
|
timeout_ms: Option<u64>,
|
|
additional_deny_read_paths: &[AbsolutePathBuf],
|
|
additional_deny_write_paths: &[AbsolutePathBuf],
|
|
tty: bool,
|
|
stdin_open: bool,
|
|
use_private_desktop: bool,
|
|
) -> Result<SpawnedProcess> {
|
|
backends::legacy::spawn_windows_sandbox_session_legacy(
|
|
permission_profile,
|
|
workspace_roots,
|
|
codex_home,
|
|
command,
|
|
cwd,
|
|
env_map,
|
|
timeout_ms,
|
|
additional_deny_read_paths,
|
|
additional_deny_write_paths,
|
|
tty,
|
|
stdin_open,
|
|
use_private_desktop,
|
|
/*private_desktop_name*/ None,
|
|
)
|
|
.await
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub async fn spawn_windows_sandbox_session_elevated_for_permission_profile(
|
|
permission_profile: &PermissionProfile,
|
|
workspace_roots: &[AbsolutePathBuf],
|
|
codex_home: &Path,
|
|
command: Vec<String>,
|
|
cwd: &Path,
|
|
env_map: HashMap<String, String>,
|
|
proxy_enforced: bool,
|
|
network_proxy_restricting_sid: Option<String>,
|
|
timeout_ms: Option<u64>,
|
|
read_roots_override: Option<&[PathBuf]>,
|
|
read_roots_include_platform_defaults: bool,
|
|
write_roots_override: Option<&[PathBuf]>,
|
|
deny_read_paths_override: &[AbsolutePathBuf],
|
|
deny_write_paths_override: &[AbsolutePathBuf],
|
|
tty: bool,
|
|
stdin_open: bool,
|
|
use_private_desktop: bool,
|
|
) -> Result<SpawnedProcess> {
|
|
backends::elevated::spawn_windows_sandbox_session_elevated_for_permission_profile(
|
|
permission_profile,
|
|
workspace_roots,
|
|
codex_home,
|
|
command,
|
|
cwd,
|
|
env_map,
|
|
proxy_enforced,
|
|
network_proxy_restricting_sid,
|
|
crate::WindowsSandboxProxySettingsMode::Reconcile,
|
|
timeout_ms,
|
|
read_roots_override,
|
|
read_roots_include_platform_defaults,
|
|
write_roots_override,
|
|
deny_read_paths_override,
|
|
deny_write_paths_override,
|
|
tty,
|
|
stdin_open,
|
|
use_private_desktop,
|
|
/*private_desktop_name*/ None,
|
|
)
|
|
.await
|
|
}
|
|
|
|
#[cfg(test)]
|
|
pub(crate) use backends::windows_common::finish_driver_spawn;
|
|
#[cfg(test)]
|
|
pub(crate) use backends::windows_common::make_runner_resizer;
|
|
#[cfg(test)]
|
|
pub(crate) use backends::windows_common::start_runner_pipe_writer;
|
|
#[cfg(test)]
|
|
pub(crate) use backends::windows_common::start_runner_stdin_writer;
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|