Delegate remote process sandboxing to the executor (#37480)

## What changed

- Preserve executor-native working directories, workspace roots, and permission profiles when preparing remote `exec_command` requests instead of resolving them through the host platform.
- Send sandbox intent to the remote executor, including a restricted-token default for Windows executors and `-NoProfile` for elevated PowerShell commands.
- Reject intercepted cross-platform `apply_patch` commands when filesystem writes are restricted, while continuing to allow them for unsandboxed or full-disk-write profiles.

## Testing

Extended remote unified-exec coverage for foreign Windows workspaces, elevated PowerShell, sandbox metadata, and restricted and unrestricted intercepted patches.

GitOrigin-RevId: 9fd328879fa2c15594fd58e40b6b32e8ba0847e7
This commit is contained in:
iceweasel-oai authored and copyberry committed 2026-08-07 18:05:17 +00:00
1 parent 92fb33b758
commit 511262b984
8 files changed
+284 -44

No files matched your search

+20 -1
View File
@@ -15,6 +15,7 @@ use crate::tools::network_approval::NetworkApprovalSpec;
use codex_file_system::FileSystemSandboxContext;
use codex_network_proxy::NetworkProxy;
use codex_protocol::approvals::ExecPolicyAmendment;
use codex_protocol::config_types::WindowsSandboxLevel;
use codex_protocol::error::CodexErr;
use codex_protocol::permissions::FileSystemSandboxKind;
use codex_protocol::permissions::FileSystemSandboxPolicy;
@@ -27,6 +28,7 @@ use codex_sandboxing::SandboxType;
use codex_sandboxing::SandboxablePreference;
use codex_sandboxing::policy_transforms::effective_permission_profile;
use codex_tools::ToolName;
use codex_utils_path_uri::PathConvention;
use codex_utils_path_uri::PathUri;
use futures::Future;
use serde::Serialize;
@@ -360,6 +362,10 @@ pub(crate) enum ToolError {
pub(crate) trait ToolRuntime<Req, Out>: Approvable<Req> + Sandboxable {
fn turn_environment<'a>(&self, req: &'a Req) -> &'a TurnEnvironment;
fn uses_executor_managed_process_sandbox(&self, _req: &Req) -> bool {
false
}
fn network_approval_spec(&self, _req: &Req, _ctx: &ToolCtx) -> Option<NetworkApprovalSpec> {
None
}
@@ -472,11 +478,24 @@ impl<'a> SandboxAttempt<'a> {
crate::sandboxing::ExecRequest::from_sandbox_exec_request(request, options, Vec::new());
exec_request.exec_server_managed_network = managed_network;
if self.sandbox_requested {
// This level comes from the orchestrator's config, so `Disabled` means Windows
// sandboxing is irrelevant on a non-Windows host. A Windows executor would instead
// treat it as unable to enforce the requested sandbox. Select its baseline restricted
// token backend while preserving explicitly configured levels and same-OS behavior.
let windows_sandbox_level = if self.windows_sandbox_level
== WindowsSandboxLevel::Disabled
&& self.sandbox_cwd.infer_path_convention() == Some(PathConvention::Windows)
&& PathConvention::native() != PathConvention::Windows
{
WindowsSandboxLevel::RestrictedToken
} else {
self.windows_sandbox_level
};
exec_request.exec_server_sandbox = Some(FileSystemSandboxContext {
permissions: exec_server_permissions.into(),
cwd: Some(exec_request.windows_sandbox_policy_cwd.clone()),
workspace_roots: self.workspace_roots.to_vec(),
windows_sandbox_level: self.windows_sandbox_level,
windows_sandbox_level,
windows_sandbox_private_desktop: self.windows_sandbox_private_desktop,
windows_sandbox_proxy_settings_mode: None,
use_legacy_landlock: self.use_legacy_landlock,