Enable network policy callbacks for remote exec (#35652)

## What changed

- Forward remote managed-network policy requests to the controller-side decider when Guardian review is enabled.
- Bound callbacks using the configured permission-hook and Guardian review timeouts, restore trusted execution attribution, and recheck live baseline policy before requesting a decision.
- Cancel pending decisions when the process or execution scope ends, and propagate EOF across the sandbox proxy bridge with half-closes.

## Testing

- Cover callback enablement, strict allowlist behavior, live policy updates, trusted attribution, and execution-scope cancellation.

GitOrigin-RevId: 83b47657c8c4546dfe98eec8b272833e96a46b7e
This commit is contained in:
viyatb-oai authored and copyberry committed 2026-07-27 18:07:31 +00:00
1 parent 976129f097
commit 462ed19a05
13 files changed
+398 -52

No files matched your search

@@ -7,7 +7,9 @@ the process manager to spawn PTYs once an ExecRequest is prepared.
use crate::command_canonicalization::canonicalize_command_for_approval;
use crate::exec::ExecCapturePolicy;
use crate::exec::ExecExpiration;
use crate::guardian::GUARDIAN_REVIEW_TIMEOUT;
use crate::guardian::GuardianNetworkAccessTrigger;
use crate::guardian::routes_approval_to_guardian;
use crate::sandboxing::ExecOptions;
use crate::sandboxing::ExecServerEnvConfig;
use crate::sandboxing::SandboxPermissions;
@@ -54,9 +56,13 @@ use codex_utils_path_uri::PathUri;
use futures::future::BoxFuture;
use std::collections::HashMap;
use std::io;
use std::time::Duration;
use tokio_util::sync::CancellationToken;
use tracing::error;
// Allow 5s for Guardian cleanup and 5s for controller processing after review.
const REMOTE_NETWORK_POLICY_DECISION_MARGIN: Duration = Duration::from_secs(10);
/// Request payload used by the unified-exec runtime after approvals and
/// sandbox preferences have been resolved for the current turn.
#[derive(Clone, Debug)]
@@ -332,9 +338,26 @@ impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRunt
let env = exec_env_for_sandbox_permissions(&req.env, launch_sandbox_permissions);
let (env, managed_network_context, network_proxy_launch) = match managed_network {
Some(network) if environment_is_remote => {
let launch = network.remote_launch_config().await.map_err(|err| {
let mut launch = network.remote_launch_config().await.map_err(|err| {
ToolError::Codex(CodexErr::Io(io::Error::other(err.to_string())))
})?;
if routes_approval_to_guardian(&ctx.turn)
&& network.remote_policy_decider().is_some()
{
let timeout = ctx
.session
.hooks()
.max_permission_request_timeout()
.saturating_add(GUARDIAN_REVIEW_TIMEOUT)
.saturating_add(REMOTE_NETWORK_POLICY_DECISION_MARGIN);
launch.policy_decision_timeout_ms =
Some(u64::try_from(timeout.as_millis()).map_err(|_| {
ToolError::Rejected(
"remote network policy decision timeout exceeds protocol limit"
.to_string(),
)
})?);
}
if !launch.proxy.enabled {
(env, None, None)
} else {
@@ -466,6 +489,7 @@ impl<'a> ToolRuntime<UnifiedExecRequest, UnifiedExecProcess> for UnifiedExecRunt
req.process_id,
&prepared.exec_request,
windows_sandbox_proxy_settings_mode,
/*network_policy_decider*/ None,
req.tty,
prepared.spawn_lifecycle,
req.turn_environment.environment.as_ref(),