Resolve workspace permissions at the sandbox launch boundary (#59530)

## What changed

Add optional executor workspace roots to `SandboxTransformRequest` and resolve symbolic workspace rules after merging additional permissions. Preserve explicit deny rules and treat an empty root list as granting no workspace access.

Route Windows restricted-token preparation through the shared transform path and use explicit roots when building its direct-spawn wrapper. Update Windows MXC debug launches to bind configured roots before adding the managed CA read grant.

## Testing

Extend sandbox manager tests to cover workspace and subpath expansion, empty root lists, deny preservation, and the roots and write permissions serialized into the Windows wrapper.

GitOrigin-RevId: 0bebdb08b67cbbc182c18b031b9d13a21a799682
This commit is contained in:
viyatb-oai
2026-11-05 00:30:20 +00:00
committed by copyberry
parent e8e3197e84
commit 9a7213ca37
11 changed files with 300 additions and 181 deletions
+23 -6
View File
@@ -25,6 +25,7 @@ use codex_protocol::config_types::SandboxMode;
use codex_protocol::models::PermissionProfile;
use codex_protocol::models::SandboxEnforcement;
use codex_protocol::permissions::NetworkSandboxPolicy;
use codex_sandboxing::SandboxType::WindowsMxc;
use codex_sandboxing::landlock::create_linux_sandbox_command_args_for_permission_profile;
#[cfg(target_os = "macos")]
use codex_sandboxing::seatbelt::CreateSeatbeltCommandArgsParams;
@@ -270,6 +271,9 @@ async fn run_command_under_sandbox(
}
permission_profile => permission_profile.clone(),
},
None if matches!(sandbox_type, SandboxType::Windows) => {
config.permissions.permission_profile().clone()
}
None => config.permissions.effective_permission_profile(),
};
if matches!(permission_profile, PermissionProfile::Disabled) && sandbox_state_disable_network {
@@ -298,7 +302,7 @@ async fn run_command_under_sandbox(
// disk config. Preserve that backend rather than weakening enforcement.
// An explicit MXC launch fails closed if the native implementation is unavailable.
let windows_sandbox_type = if sandbox_state.as_ref().is_some_and(|state| state.use_mxc) {
codex_sandboxing::SandboxType::WindowsMxc
WindowsMxc
} else {
config.effective_local_windows_sandbox_type()
};
@@ -327,7 +331,10 @@ async fn run_command_under_sandbox(
if let SandboxType::Windows = sandbox_type {
#[cfg(target_os = "windows")]
{
if windows_sandbox_type != codex_sandboxing::SandboxType::WindowsMxc {
if windows_sandbox_type != WindowsMxc {
if sandbox_state.is_none() {
permission_profile = config.permissions.effective_permission_profile();
}
let workspace_roots = config
.effective_workspace_roots()
.iter()
@@ -382,9 +389,10 @@ async fn run_command_under_sandbox(
// policy came from managed requirements.
#[cfg(any(target_os = "macos", target_os = "windows"))]
let enforce_managed_network = network.is_some();
let managed_mitm_ca_trust_bundle_path = match network.as_ref() {
Some(network) => network.managed_mitm_ca_trust_bundle_path(),
None => None,
// MXC adds the CA read grant in transform after binding the workspace roots.
let managed_mitm_ca_trust_bundle_path = match (network.as_ref(), &sandbox_type) {
(None, _) | (_, SandboxType::Windows) => None,
(Some(network), _) => network.managed_mitm_ca_trust_bundle_path(),
};
let runtime_permission_profile = with_managed_mitm_ca_readable_root(
permission_profile,
@@ -486,6 +494,14 @@ async fn run_command_under_sandbox(
.context("sandbox command must not be empty")?;
let sandbox_policy_cwd = PathUri::from_abs_path(&sandbox_policy_cwd);
let codex_self_exe = std::env::current_exe()?;
let workspace_roots = sandbox_state.is_none().then(|| {
config
.permissions
.workspace_roots()
.iter()
.map(PathUri::from_abs_path)
.collect::<Vec<_>>()
});
let request = SandboxManager::new().transform(SandboxTransformRequest {
command: SandboxCommand {
program: program.into(),
@@ -496,7 +512,8 @@ async fn run_command_under_sandbox(
additional_permissions: None,
},
permissions: &runtime_permission_profile,
sandbox: codex_sandboxing::SandboxType::WindowsMxc,
workspace_roots: workspace_roots.as_deref(),
sandbox: WindowsMxc,
enforce_managed_network,
environment_id: None,
network: network.as_ref(),