Enforce configured network proxy in codex sandbox (#27035)

## Why

`codex sandbox` can start a network proxy from a configured permission
profile. Previously, sandbox-level containment was tied to managed
network requirements rather than whether a proxy was actually active.
This meant config-driven proxy policies were not consistently enforced
as the sandbox's only network path.

## What changed

- Enable proxy-only network containment whenever `codex sandbox` starts
a network proxy.
- Apply the same active-proxy check to the macOS and Linux sandbox
paths.
- Add a Linux regression test that verifies a sandboxed command cannot
establish a direct connection while the configured proxy is active.

## Test plan

- `just test -p codex-cli debug_sandbox::tests`
- `sandbox_with_network_proxy_blocks_direct_loopback_access` runs on
Linux to cover the config-driven proxy path end to end.
This commit is contained in:
viyatb-oai
2026-06-08 14:03:37 -07:00
committed by GitHub
Unverified
parent e0ee491df3
commit 85fd52f7e4
7 changed files with 98 additions and 8 deletions
+5 -2
View File
@@ -258,6 +258,9 @@ async fn run_command_under_sandbox(
let network = network_proxy
.as_ref()
.map(codex_core::config::StartedNetworkProxy::proxy);
// Proxy containment depends on whether a proxy is active, not whether its
// policy came from managed requirements.
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,
@@ -278,7 +281,7 @@ async fn run_command_under_sandbox(
file_system_sandbox_policy: &file_system_sandbox_policy,
network_sandbox_policy,
sandbox_policy_cwd: sandbox_policy_cwd.as_path(),
enforce_managed_network: false,
enforce_managed_network,
network: network.as_ref(),
extra_allow_unix_sockets: allow_unix_sockets,
});
@@ -311,7 +314,7 @@ async fn run_command_under_sandbox(
&runtime_permission_profile,
sandbox_policy_cwd.as_path(),
use_legacy_landlock,
allow_network_for_proxy(managed_network_requirements_enabled),
allow_network_for_proxy(enforce_managed_network),
);
spawn_debug_sandbox_child(
codex_linux_sandbox_exe,