Add hidden Windows sandbox wrapper entrypoint (#28358)

## Why

This is the second PR in the Windows fs-helper sandbox stack. The
fs-helper path needs a Windows sandbox launcher that has the same
argv-shaped contract as macOS `sandbox-exec` and `codex-linux-sandbox`,
but this PR only introduces that hidden launcher. It does not route
fs-helper through it yet.

The hidden launcher still needs to be policy-complete before later
direct-spawn callers use it. In particular, it has to carry the same
Windows sandbox policy details that the existing spawn paths already
understand: proxy enforcement, read/write root overrides, and
deny-read/deny-write overrides.

## What Changed

- Added the hidden `codex.exe --run-as-windows-sandbox` arg1 dispatch
path.
- Added `windows-sandbox-rs/src/wrapper.rs`, which parses the wrapper
argv, launches the requested command through the shared Windows sandbox
session runner from PR1, and forwards stdio.
- Added `create_windows_sandbox_command_args_for_permission_profile()`
so later direct-spawn callers can build the wrapper argv consistently.
- Made the wrapper argv round-trip the full Windows sandbox policy
surface it needs later: workspace roots, environment, permission
profile, sandbox level, private desktop, proxy enforcement, read/write
root overrides, and deny-read/deny-write overrides.
- Carried `proxy_enforced` through the shared Windows session request so
proxy-managed executions continue to use the offline/elevated sandbox
identity.
- Added wrapper argument round-trip coverage for the full policy fields.

## Verification

- `just test -p codex-windows-sandbox windows_wrapper_args_round_trip`
- `just test -p codex-arg0`
- `just test -p codex-core exec::tests::windows_`
- `just fix -p codex-windows-sandbox -p codex-core -p codex-cli`

Local note: the full `just fmt` command still fails on this workstation
in non-Rust formatter setup (`uv` cache access denied and missing
`dotslash`/buildifier), but the Rust formatter phase completed.
This commit is contained in:
iceweasel-oai authored and GitHub committed 2026-06-15 21:30:32 +00:00
1 parent e7a9988d1a
commit fbbe7706d6
11 files changed
+491 -39

No files matched your search

@@ -55,6 +55,7 @@ pub(crate) async fn spawn_windows_sandbox_session_elevated_for_permission_profil
command: Vec<String>,
cwd: &Path,
mut env_map: HashMap<String, String>,
proxy_enforced: bool,
timeout_ms: Option<u64>,
read_roots_override: Option<&[PathBuf]>,
read_roots_include_platform_defaults: bool,
@@ -89,6 +90,7 @@ pub(crate) async fn spawn_windows_sandbox_session_elevated_for_permission_profil
write_roots_override,
&deny_read_paths_override,
&deny_write_paths_override,
proxy_enforced,
)?;
let spawn_request = SpawnRequest {
@@ -30,6 +30,7 @@ pub struct WindowsSandboxSessionRequest<'a> {
pub cwd: &'a Path,
pub env_map: HashMap<String, String>,
pub windows_sandbox_level: WindowsSandboxLevel,
pub proxy_enforced: bool,
pub timeout_ms: Option<u64>,
pub read_roots_override: Option<&'a [PathBuf]>,
pub read_roots_include_platform_defaults: bool,
@@ -44,44 +45,44 @@ pub struct WindowsSandboxSessionRequest<'a> {
pub async fn spawn_windows_sandbox_session_for_level(
request: WindowsSandboxSessionRequest<'_>,
) -> Result<SpawnedProcess> {
match request.windows_sandbox_level {
WindowsSandboxLevel::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.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,
)
.await
}
WindowsSandboxLevel::RestrictedToken | WindowsSandboxLevel::Disabled => {
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,
)
.await
}
if request.proxy_enforced
|| matches!(request.windows_sandbox_level, WindowsSandboxLevel::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.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,
)
.await
} else {
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,
)
.await
}
}
@@ -125,6 +126,7 @@ pub async fn spawn_windows_sandbox_session_elevated_for_permission_profile(
command: Vec<String>,
cwd: &Path,
env_map: HashMap<String, String>,
proxy_enforced: bool,
timeout_ms: Option<u64>,
read_roots_override: Option<&[PathBuf]>,
read_roots_include_platform_defaults: bool,
@@ -142,6 +144,7 @@ pub async fn spawn_windows_sandbox_session_elevated_for_permission_profile(
command,
cwd,
env_map,
proxy_enforced,
timeout_ms,
read_roots_override,
read_roots_include_platform_defaults,