mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Keep sandbox preparation with the command through launch (#62205)
## What changed - Keep the prepared `SandboxExecRequest` intact in core and let `command/exec` borrow the prepared command for streaming. Windows restricted-token commands continue through the dedicated sandbox launcher. - Move runtime read-path selection for exec-server commands and filesystem helpers into `SandboxManager`. It derives the paths from the executor's binaries and, for managed process launches, finds the generated proxy CA bundle in the command environment. GitOrigin-RevId: 8c9d278496d84589bc4a7b7d0ed08cb1b8e6ba21
This commit is contained in:
@@ -5,6 +5,7 @@ use std::time::Duration;
|
||||
use codex_exec_server_protocol::JSONRPCErrorError;
|
||||
use codex_sandboxing::SandboxCommand;
|
||||
use codex_sandboxing::SandboxExecRequest;
|
||||
use codex_sandboxing::SandboxExecutables;
|
||||
use codex_sandboxing::SandboxManager;
|
||||
use codex_sandboxing::SandboxTransformRequest;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
@@ -88,16 +89,6 @@ impl FileSystemSandboxRunner {
|
||||
sandbox: &FileSystemSandboxContext,
|
||||
) -> Result<SandboxExecRequest, JSONRPCErrorError> {
|
||||
let helper = &self.runtime_paths.codex_self_exe;
|
||||
let mut helper_readable_paths = Vec::new();
|
||||
if !sandbox.use_legacy_landlock {
|
||||
helper_readable_paths.push(helper.clone());
|
||||
if let Some(linux_helper) = &self.runtime_paths.codex_linux_sandbox_exe
|
||||
&& linux_helper != helper
|
||||
{
|
||||
helper_readable_paths.push(linux_helper.clone());
|
||||
}
|
||||
}
|
||||
|
||||
let sandbox_manager = SandboxManager::for_file_system_helpers()
|
||||
.with_linux_sandbox_pid_namespace(self.runtime_paths.linux_sandbox_pid_namespace);
|
||||
#[cfg(target_os = "macos")]
|
||||
@@ -128,14 +119,13 @@ impl FileSystemSandboxRunner {
|
||||
command,
|
||||
permissions: &sandbox.permissions,
|
||||
workspace_roots: Some(&sandbox.workspace_roots),
|
||||
runtime_readable_paths: Some(&helper_readable_paths),
|
||||
selection,
|
||||
network: Default::default(),
|
||||
sandbox_policy_cwd: &sandbox.cwd,
|
||||
sandbox_exe: if cfg!(windows) {
|
||||
Some(helper.as_path())
|
||||
} else {
|
||||
self.runtime_paths.codex_linux_sandbox_exe.as_deref()
|
||||
executables: SandboxExecutables::Executor {
|
||||
codex: helper,
|
||||
linux_sandbox: self.runtime_paths.codex_linux_sandbox_exe.as_ref(),
|
||||
arg0: None,
|
||||
},
|
||||
use_legacy_landlock: sandbox.use_legacy_landlock,
|
||||
windows_sandbox_level,
|
||||
|
||||
@@ -7,8 +7,6 @@ use crate::process_telemetry::ProcessTelemetry;
|
||||
use codex_exec_server_protocol::JSONRPCErrorError;
|
||||
use codex_exec_server_protocol::ProcessStartErrorData;
|
||||
use codex_file_system::WindowsSandboxSelection;
|
||||
use codex_network_proxy::CHILD_ONLY_CA_ENV_KEYS;
|
||||
use codex_network_proxy::CUSTOM_CA_ENV_KEYS;
|
||||
use codex_network_proxy::ManagedNetworkSandboxContext;
|
||||
use codex_network_proxy::ManagedProxyRouting;
|
||||
use codex_network_proxy::NetworkPolicyAuditObserver;
|
||||
@@ -18,15 +16,14 @@ use codex_network_proxy::NetworkProxyHandle;
|
||||
use codex_network_proxy::NetworkProxyState;
|
||||
use codex_network_proxy::RemoteCredentialBrokerCache;
|
||||
use codex_network_proxy::ShellStartupCredentials;
|
||||
use codex_network_proxy::is_managed_mitm_ca_trust_bundle_path;
|
||||
use codex_sandboxing::SandboxCommand;
|
||||
use codex_sandboxing::SandboxExecutables;
|
||||
use codex_sandboxing::SandboxManager;
|
||||
use codex_sandboxing::SandboxNetwork;
|
||||
use codex_sandboxing::SandboxTransformRequest;
|
||||
use codex_sandboxing::WrappedSandboxCommand;
|
||||
#[cfg(windows)]
|
||||
use codex_shell_command::shell_detect::fallback_powershell_shell_for_windows_sandbox;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
|
||||
#[cfg(unix)]
|
||||
@@ -100,28 +97,6 @@ pub(crate) async fn prepare_exec_request_with_telemetry(
|
||||
"sandbox runtime paths are not configured".to_string(),
|
||||
))
|
||||
})?;
|
||||
let mut runtime_readable_paths = Vec::new();
|
||||
if cfg!(target_os = "linux") || (cfg!(unix) && params.arg0.is_some()) {
|
||||
runtime_readable_paths.push(runtime_paths.codex_self_exe.clone());
|
||||
}
|
||||
if cfg!(target_os = "linux") {
|
||||
runtime_readable_paths.extend(runtime_paths.codex_linux_sandbox_exe.iter().cloned());
|
||||
}
|
||||
let managed_mitm_ca_trust_bundle_path = if managed_network.is_some() {
|
||||
CUSTOM_CA_ENV_KEYS
|
||||
.into_iter()
|
||||
.chain(CHILD_ONLY_CA_ENV_KEYS)
|
||||
.find_map(|key| {
|
||||
let path = env.get(key)?;
|
||||
if !is_managed_mitm_ca_trust_bundle_path(path) {
|
||||
return None;
|
||||
}
|
||||
AbsolutePathBuf::from_absolute_path(path).ok()
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
runtime_readable_paths.extend(managed_mitm_ca_trust_bundle_path);
|
||||
let sandbox_manager = SandboxManager::new()
|
||||
.with_linux_sandbox_pid_namespace(runtime_paths.linux_sandbox_pid_namespace)
|
||||
.with_linux_sandbox_transparent_tcp(runtime_paths.linux_sandbox_transparent_tcp);
|
||||
@@ -186,7 +161,6 @@ pub(crate) async fn prepare_exec_request_with_telemetry(
|
||||
},
|
||||
permissions: &sandbox_context.permissions,
|
||||
workspace_roots: Some(&sandbox_context.workspace_roots),
|
||||
runtime_readable_paths: Some(&runtime_readable_paths),
|
||||
selection,
|
||||
network: SandboxNetwork::new(
|
||||
enforce_managed_network,
|
||||
@@ -194,10 +168,10 @@ pub(crate) async fn prepare_exec_request_with_telemetry(
|
||||
/*environment_id*/ None,
|
||||
),
|
||||
sandbox_policy_cwd: &sandbox_context.cwd,
|
||||
sandbox_exe: if cfg!(windows) {
|
||||
Some(runtime_paths.codex_self_exe.as_path())
|
||||
} else {
|
||||
runtime_paths.codex_linux_sandbox_exe.as_deref()
|
||||
executables: SandboxExecutables::Executor {
|
||||
codex: &runtime_paths.codex_self_exe,
|
||||
linux_sandbox: runtime_paths.codex_linux_sandbox_exe.as_ref(),
|
||||
arg0: params.arg0.as_deref(),
|
||||
},
|
||||
use_legacy_landlock: sandbox_context.use_legacy_landlock,
|
||||
windows_sandbox_level,
|
||||
|
||||
Reference in New Issue
Block a user