From ca9b26ecaed9273449b1cfdbb57334cb62bff142 Mon Sep 17 00:00:00 2001 From: viyatb-oai Date: Tue, 7 Jul 2026 09:43:38 -0700 Subject: [PATCH] fix(core): preserve managed network during escalation Co-authored-by: Codex noreply@openai.com --- codex-rs/core/src/tools/orchestrator.rs | 7 +++++-- codex-rs/core/src/tools/sandboxing.rs | 8 +++++++- codex-rs/core/src/tools/sandboxing_tests.rs | 18 +++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/codex-rs/core/src/tools/orchestrator.rs b/codex-rs/core/src/tools/orchestrator.rs index ba427b00c4..55c8cb6c0e 100644 --- a/codex-rs/core/src/tools/orchestrator.rs +++ b/codex-rs/core/src/tools/orchestrator.rs @@ -227,8 +227,11 @@ impl ToolOrchestrator { &file_system_sandbox_policy, ); let managed_network_active = turn_ctx.network.is_some(); - let escalation_profile = - escalation_profile_preserving_deny_read(sandbox_override, &turn_ctx.permission_profile); + let escalation_profile = escalation_profile_preserving_deny_read( + sandbox_override, + managed_network_active, + &turn_ctx.permission_profile, + ); let attempt_permissions = escalation_profile .as_ref() .unwrap_or(&turn_ctx.permission_profile); diff --git a/codex-rs/core/src/tools/sandboxing.rs b/codex-rs/core/src/tools/sandboxing.rs index 7df5cbbb27..b87c85398f 100644 --- a/codex-rs/core/src/tools/sandboxing.rs +++ b/codex-rs/core/src/tools/sandboxing.rs @@ -285,6 +285,7 @@ pub(crate) fn sandbox_override_for_first_attempt( /// administrator-defined deny-read restrictions. pub(crate) fn escalation_profile_preserving_deny_read( sandbox_override: SandboxOverride, + managed_network_active: bool, permission_profile: &PermissionProfile, ) -> Option { if !matches!( @@ -297,11 +298,16 @@ pub(crate) fn escalation_profile_preserving_deny_read( let mut file_system_policy = FileSystemSandboxPolicy::unrestricted(); file_system_policy .preserve_deny_read_restrictions_from(&permission_profile.file_system_sandbox_policy()); + let network_sandbox_policy = if managed_network_active { + permission_profile.network_sandbox_policy() + } else { + NetworkSandboxPolicy::Enabled + }; Some( PermissionProfile::from_runtime_permissions_with_enforcement( permission_profile.enforcement(), &file_system_policy, - NetworkSandboxPolicy::Enabled, + network_sandbox_policy, ), ) } diff --git a/codex-rs/core/src/tools/sandboxing_tests.rs b/codex-rs/core/src/tools/sandboxing_tests.rs index b694848d02..632388f235 100644 --- a/codex-rs/core/src/tools/sandboxing_tests.rs +++ b/codex-rs/core/src/tools/sandboxing_tests.rs @@ -208,6 +208,7 @@ fn deny_read_is_preserved_during_explicit_escalation_and_policy_bypass() { ); let escalated = escalation_profile_preserving_deny_read( SandboxOverride::EscalatedSandboxWithDenyRead, + /*managed_network_active*/ false, &permission_profile, ) .expect("escalation profile"); @@ -243,10 +244,25 @@ fn deny_read_is_preserved_during_explicit_escalation_and_policy_bypass() { /*has_managed_network_requirements*/ false, )); assert_eq!( - escalation_profile_preserving_deny_read(SandboxOverride::NoOverride, &permission_profile,), + escalation_profile_preserving_deny_read( + SandboxOverride::NoOverride, + /*managed_network_active*/ false, + &permission_profile, + ), None, "ordinary sandboxed attempts keep their original profile", ); + let managed_network_escalation = escalation_profile_preserving_deny_read( + SandboxOverride::EscalatedSandboxWithDenyRead, + /*managed_network_active*/ true, + &permission_profile, + ) + .expect("managed network escalation profile"); + assert_eq!( + managed_network_escalation.network_sandbox_policy(), + NetworkSandboxPolicy::Restricted, + "managed network restrictions must survive escalation", + ); } #[test]