mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
Preserve sandbox overrides across execution requests (#51786)
## What changed Move `SandboxOverride` into the shared protocol and carry the controller's selection through tool attempts, execution requests, and exec-server process and filesystem sandbox preparation. Include it as `sandboxOverride` in filesystem sandbox contexts for observation without granting broader permissions or altering sandbox commands. Default missing values to `NoOverride` and omit that value when serializing to preserve compatibility with existing requests. ## Testing Extend tests to cover override propagation, wire round-trips for all three variants, and deserialization of requests without `sandboxOverride`. GitOrigin-RevId: 2f438cf4aef1134e3149959d14aa731682168ae5
This commit is contained in:
@@ -99,6 +99,7 @@ use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_protocol::protocol::TurnEnvironmentSelections;
|
||||
use codex_protocol::request_permissions::PermissionGrantScope;
|
||||
use codex_protocol::request_permissions::RequestPermissionProfile;
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use codex_protocol::turn_input::TurnInput as SubmittedTurnInput;
|
||||
use codex_protocol::turn_input::TurnInputMode;
|
||||
use codex_protocol::turn_input::TurnInputRequest;
|
||||
@@ -10177,6 +10178,7 @@ async fn capability_discovery_uses_environment_permission_profile() {
|
||||
environment_config.windows_sandbox_level = WindowsSandboxLevel::Elevated;
|
||||
environment_config.use_legacy_landlock = true;
|
||||
let expected_sandbox = FileSystemSandboxContext {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
permissions: environment.permission_profile().clone(),
|
||||
cwd: environment.cwd().clone(),
|
||||
workspace_roots: environment.workspace_roots().to_vec(),
|
||||
|
||||
@@ -35,6 +35,7 @@ use codex_protocol::protocol::ErrorEvent;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::TurnEnvironmentSelection;
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use codex_protocol::turn_input::CyberAccessProgram;
|
||||
use codex_sandboxing::policy_transforms::effective_permission_profile;
|
||||
use codex_sandboxing::policy_transforms::merge_permission_profiles;
|
||||
@@ -242,6 +243,7 @@ impl TurnEnvironment {
|
||||
additional_permissions.as_ref(),
|
||||
);
|
||||
FileSystemSandboxContext {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
permissions,
|
||||
cwd: self.cwd().clone(),
|
||||
workspace_roots: self.workspace_roots().to_vec(),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use core_test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::tempdir;
|
||||
@@ -34,6 +35,7 @@ async fn snapshot_failure_omits_credentials_and_stops_descendants(
|
||||
let permissions = PermissionProfile::Disabled;
|
||||
let manager = SandboxManager::new();
|
||||
let attempt = SandboxAttempt {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
sandbox: SandboxType::None,
|
||||
sandbox_requested: false,
|
||||
permissions: &permissions,
|
||||
|
||||
@@ -17,6 +17,8 @@ use codex_network_proxy::NetworkProxyConfig;
|
||||
use codex_protocol::config_types::EnvironmentVariablePattern;
|
||||
#[cfg(unix)]
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
#[cfg(unix)]
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use core_test_support::PathBufExt;
|
||||
use core_test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -411,6 +413,7 @@ async fn inactive_profiles_keep_snapshots_but_active_brokers_require_sandbox() -
|
||||
let permissions = PermissionProfile::Disabled;
|
||||
let cancellation = CancellationToken::new();
|
||||
let mut attempt = SandboxAttempt {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
sandbox: SandboxType::None,
|
||||
sandbox_requested: false,
|
||||
permissions: &permissions,
|
||||
|
||||
@@ -23,6 +23,7 @@ use crate::tools::sandboxing::ToolCtx;
|
||||
use crate::tools::sandboxing::ToolError;
|
||||
use crate::tools::sandboxing::ToolRuntime;
|
||||
use crate::tools::sandboxing::default_exec_approval_requirement;
|
||||
use crate::tools::sandboxing::ensure_native_sandbox;
|
||||
use crate::tools::sandboxing::sandbox_override_for_first_attempt;
|
||||
use crate::tools::sandboxing::unsandboxed_execution_allowed;
|
||||
use codex_otel::ToolDecisionSource;
|
||||
@@ -83,6 +84,7 @@ impl ToolOrchestrator {
|
||||
tool_name: tool_ctx.tool_name.clone(),
|
||||
};
|
||||
let attempt_with_network_approval = SandboxAttempt {
|
||||
sandbox_override: attempt.sandbox_override,
|
||||
sandbox: attempt.sandbox,
|
||||
sandbox_requested: attempt.sandbox_requested,
|
||||
permissions: attempt.permissions,
|
||||
@@ -347,7 +349,7 @@ impl ToolOrchestrator {
|
||||
SandboxType::None
|
||||
};
|
||||
if !executor_managed_process_sandbox {
|
||||
sandbox_override.ensure_native_sandbox(initial_sandbox)?;
|
||||
ensure_native_sandbox(sandbox_override, initial_sandbox)?;
|
||||
}
|
||||
|
||||
let sandbox_policy_cwd = tool
|
||||
@@ -360,6 +362,7 @@ impl ToolOrchestrator {
|
||||
turn_ctx.config.codex_linux_sandbox_exe.as_ref()
|
||||
};
|
||||
let initial_attempt = SandboxAttempt {
|
||||
sandbox_override,
|
||||
sandbox: initial_sandbox,
|
||||
sandbox_requested,
|
||||
permissions: initial_permissions,
|
||||
@@ -534,6 +537,7 @@ impl ToolOrchestrator {
|
||||
codex_sandbox_exe
|
||||
};
|
||||
let retry_attempt = SandboxAttempt {
|
||||
sandbox_override,
|
||||
sandbox: retry_sandbox,
|
||||
sandbox_requested: retry_sandbox_requested,
|
||||
permissions: initial_permissions,
|
||||
|
||||
@@ -98,6 +98,7 @@ impl ApplyPatchRuntime {
|
||||
req.additional_permissions.as_ref(),
|
||||
);
|
||||
Some(FileSystemSandboxContext {
|
||||
sandbox_override: attempt.sandbox_override,
|
||||
permissions,
|
||||
cwd: attempt.sandbox_cwd.clone(),
|
||||
workspace_roots: attempt.workspace_roots.to_vec(),
|
||||
|
||||
@@ -11,6 +11,7 @@ use codex_protocol::protocol::EnvironmentConfig;
|
||||
use codex_protocol::protocol::EnvironmentConfigState;
|
||||
use codex_protocol::protocol::GranularApprovalConfig;
|
||||
use codex_protocol::protocol::TurnEnvironmentSelection;
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use codex_sandboxing::SandboxManager;
|
||||
use codex_sandboxing::SandboxType;
|
||||
use codex_sandboxing::policy_transforms::effective_file_system_sandbox_policy;
|
||||
@@ -239,6 +240,7 @@ async fn file_system_sandbox_context_preserves_executor_workspace_permissions()
|
||||
let manager = SandboxManager::new();
|
||||
let sandbox_policy_cwd = PathUri::from_abs_path(&path);
|
||||
let attempt = SandboxAttempt {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
sandbox: SandboxType::MacosSeatbelt,
|
||||
sandbox_requested: true,
|
||||
permissions: &permissions,
|
||||
@@ -306,6 +308,7 @@ async fn file_system_sandbox_context_respects_sandbox_request() {
|
||||
let manager = SandboxManager::new();
|
||||
let sandbox_policy_cwd = PathUri::from_abs_path(&path);
|
||||
let attempt = SandboxAttempt {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
sandbox: SandboxType::None,
|
||||
sandbox_requested: false,
|
||||
permissions: &permissions,
|
||||
@@ -343,6 +346,7 @@ async fn file_system_sandbox_context_respects_sandbox_request() {
|
||||
assert_eq!(
|
||||
ApplyPatchRuntime::file_system_sandbox_context_for_attempt(&req, &attempt),
|
||||
Some(FileSystemSandboxContext {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
permissions,
|
||||
cwd: cwd.clone(),
|
||||
workspace_roots: vec![cwd],
|
||||
|
||||
@@ -21,6 +21,7 @@ use codex_network_proxy::PROXY_ENV_KEYS;
|
||||
use codex_network_proxy::PROXY_GIT_SSH_COMMAND_ENV_KEY;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use codex_sandboxing::SandboxManager;
|
||||
use codex_sandboxing::SandboxType;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
@@ -119,6 +120,7 @@ async fn explicit_escalation_prepares_exec_without_managed_network() -> anyhow::
|
||||
let permissions = PermissionProfile::Disabled;
|
||||
let manager = SandboxManager::new();
|
||||
let attempt = SandboxAttempt {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
sandbox: SandboxType::None,
|
||||
sandbox_requested: false,
|
||||
permissions: &permissions,
|
||||
|
||||
@@ -22,6 +22,7 @@ use codex_protocol::permissions::FileSystemSandboxKind;
|
||||
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::ReviewDecision;
|
||||
pub(crate) use codex_protocol::sandbox::SandboxOverride;
|
||||
use codex_sandboxing::SandboxCommand;
|
||||
use codex_sandboxing::SandboxManager;
|
||||
use codex_sandboxing::SandboxTransformRequest;
|
||||
@@ -230,23 +231,19 @@ pub(crate) fn default_exec_approval_requirement(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum SandboxOverride {
|
||||
NoOverride,
|
||||
EscalatedSandboxWithRestrictions,
|
||||
BypassSandboxFirstAttempt,
|
||||
}
|
||||
|
||||
impl SandboxOverride {
|
||||
pub(crate) fn ensure_native_sandbox(self, sandbox: SandboxType) -> Result<(), ToolError> {
|
||||
if self == Self::EscalatedSandboxWithRestrictions && sandbox == SandboxType::None {
|
||||
return Err(ToolError::Rejected(
|
||||
"command escalation with denied reads requires an available filesystem sandbox"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
pub(crate) fn ensure_native_sandbox(
|
||||
sandbox_override: SandboxOverride,
|
||||
sandbox: SandboxType,
|
||||
) -> Result<(), ToolError> {
|
||||
if sandbox_override == SandboxOverride::EscalatedSandboxWithRestrictions
|
||||
&& sandbox == SandboxType::None
|
||||
{
|
||||
return Err(ToolError::Rejected(
|
||||
"command escalation with denied reads requires an available filesystem sandbox"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn sandbox_override_for_first_attempt(
|
||||
@@ -402,6 +399,7 @@ pub(crate) trait ToolRuntime<Req, Out>: Approvable<Req> + Sandboxable {
|
||||
}
|
||||
|
||||
pub(crate) struct SandboxAttempt<'a> {
|
||||
pub sandbox_override: SandboxOverride,
|
||||
pub sandbox: SandboxType,
|
||||
/// Whether policy requested sandboxing, independent of this host's concrete wrapper.
|
||||
pub sandbox_requested: bool,
|
||||
@@ -497,7 +495,7 @@ impl<'a> SandboxAttempt<'a> {
|
||||
environment_id: Option<&str>,
|
||||
) -> Result<crate::sandboxing::ExecRequest, CodexErr> {
|
||||
let network = self.network_proxy(network);
|
||||
let request = self
|
||||
let mut request = self
|
||||
.manager
|
||||
.transform(SandboxTransformRequest {
|
||||
command,
|
||||
@@ -512,6 +510,7 @@ impl<'a> SandboxAttempt<'a> {
|
||||
windows_sandbox_level: self.windows_sandbox_level,
|
||||
})
|
||||
.map_err(CodexErr::from)?;
|
||||
request.sandbox_override = self.sandbox_override;
|
||||
let workspace_roots = self
|
||||
.workspace_roots
|
||||
.iter()
|
||||
@@ -530,7 +529,7 @@ impl<'a> SandboxAttempt<'a> {
|
||||
self.exec_server_permissions,
|
||||
command.additional_permissions.as_ref(),
|
||||
);
|
||||
let request = self
|
||||
let mut request = self
|
||||
.manager
|
||||
.transform(SandboxTransformRequest {
|
||||
command,
|
||||
@@ -546,6 +545,7 @@ impl<'a> SandboxAttempt<'a> {
|
||||
windows_sandbox_level: self.windows_sandbox_level,
|
||||
})
|
||||
.map_err(CodexErr::from)?;
|
||||
request.sandbox_override = self.sandbox_override;
|
||||
let mut exec_request = crate::sandboxing::ExecRequest::from_sandbox_exec_request(
|
||||
request,
|
||||
options,
|
||||
@@ -555,6 +555,7 @@ impl<'a> SandboxAttempt<'a> {
|
||||
if self.sandbox_requested {
|
||||
exec_request.exec_server_sandbox = Some(FileSystemSandboxContext {
|
||||
permissions: exec_server_permissions,
|
||||
sandbox_override: self.sandbox_override,
|
||||
cwd: exec_request.windows_sandbox_policy_cwd.clone(),
|
||||
workspace_roots: self.workspace_roots.to_vec(),
|
||||
user_home_dir: None,
|
||||
|
||||
@@ -8,6 +8,7 @@ use codex_protocol::permissions::FileSystemSandboxEntry;
|
||||
use codex_protocol::permissions::FileSystemSpecialPath;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::GranularApprovalConfig;
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use codex_sandboxing::SandboxCommand;
|
||||
use codex_sandboxing::SandboxManager;
|
||||
use codex_sandboxing::SandboxType;
|
||||
@@ -210,7 +211,7 @@ fn deny_read_preserves_the_sandbox_for_explicit_escalation_and_blocks_policy_byp
|
||||
);
|
||||
assert!(!unsandboxed_execution_allowed(&file_system_policy));
|
||||
assert!(matches!(
|
||||
SandboxOverride::EscalatedSandboxWithRestrictions.ensure_native_sandbox(SandboxType::None),
|
||||
ensure_native_sandbox(SandboxOverride::EscalatedSandboxWithRestrictions, SandboxType::None),
|
||||
Err(ToolError::Rejected(reason)) if reason.contains("requires an available filesystem sandbox"),
|
||||
));
|
||||
assert_eq!(
|
||||
@@ -292,6 +293,7 @@ fn windows_sandbox_env_preserves_denied_reads_or_rejects_unsupported_backend() {
|
||||
let cwd_uri = PathUri::from_abs_path(&cwd);
|
||||
let manager = SandboxManager::new();
|
||||
let mut attempt = SandboxAttempt {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
sandbox: SandboxType::WindowsRestrictedToken,
|
||||
sandbox_requested: true,
|
||||
permissions: &permissions,
|
||||
@@ -363,6 +365,7 @@ fn exec_server_env_keeps_command_native_and_carries_sandbox_context() {
|
||||
.materialize_project_roots_with_workspace_roots(std::slice::from_ref(&cwd));
|
||||
let manager = SandboxManager::new();
|
||||
let mut attempt = SandboxAttempt {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
sandbox: SandboxType::None,
|
||||
sandbox_requested: true,
|
||||
permissions: &permissions,
|
||||
@@ -413,6 +416,7 @@ fn exec_server_env_keeps_command_native_and_carries_sandbox_context() {
|
||||
assert_eq!(
|
||||
request.exec_server_sandbox,
|
||||
Some(codex_exec_server::FileSystemSandboxContext {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
permissions: exec_server_permissions.clone(),
|
||||
cwd: cwd_uri.clone(),
|
||||
workspace_roots: vec![cwd_uri.clone()],
|
||||
@@ -433,6 +437,17 @@ fn exec_server_env_keeps_command_native_and_carries_sandbox_context() {
|
||||
Some(managed_network.clone())
|
||||
);
|
||||
|
||||
attempt.sandbox_override = SandboxOverride::EscalatedSandboxWithRestrictions;
|
||||
let escalated_request = attempt
|
||||
.env_for_exec_server(command(), options())
|
||||
.expect("prepare approved escalation with retained sandbox restrictions");
|
||||
let mut expected_context = request.exec_server_sandbox.expect("sandbox context");
|
||||
expected_context.sandbox_override = SandboxOverride::EscalatedSandboxWithRestrictions;
|
||||
assert_eq!(
|
||||
escalated_request.exec_server_sandbox,
|
||||
Some(expected_context)
|
||||
);
|
||||
|
||||
attempt.sandbox_requested = false;
|
||||
let request = attempt
|
||||
.env_for_exec_server(command(), options())
|
||||
|
||||
@@ -7,6 +7,7 @@ use codex_exec_server::ShellInfo;
|
||||
use codex_exec_server::ShellSnapshotRequest;
|
||||
use codex_features::Feature;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use codex_sandboxing::SandboxManager;
|
||||
use codex_sandboxing::SandboxablePreference;
|
||||
use codex_tools::ToolName;
|
||||
@@ -92,6 +93,7 @@ impl Session {
|
||||
/*has_managed_network_requirements*/ false,
|
||||
)
|
||||
.then(|| FileSystemSandboxContext {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
permissions: environment.permission_profile().clone(),
|
||||
cwd: environment.cwd().clone(),
|
||||
workspace_roots: environment.workspace_roots().to_vec(),
|
||||
|
||||
@@ -1224,6 +1224,7 @@ mod base64_bytes {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::CapabilityRootDiscoverRequest;
|
||||
use super::WireExecParams;
|
||||
#[test]
|
||||
fn discovery_v2_support_defaults_off_for_older_executors() -> serde_json::Result<()> {
|
||||
let legacy: super::EnvironmentCapabilities = serde_json::from_value(serde_json::json!({}))?;
|
||||
@@ -1269,6 +1270,7 @@ mod tests {
|
||||
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
||||
use codex_protocol::permissions::FileSystemSpecialPath;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashMap;
|
||||
@@ -1378,6 +1380,35 @@ mod tests {
|
||||
assert!(legacy_serialized.get("threadId").is_none());
|
||||
assert!(legacy_serialized.get("toolCallId").is_none());
|
||||
assert!(legacy_serialized.get("metadata").is_none());
|
||||
|
||||
for sandbox_override in [
|
||||
SandboxOverride::NoOverride,
|
||||
SandboxOverride::EscalatedSandboxWithRestrictions,
|
||||
SandboxOverride::BypassSandboxFirstAttempt,
|
||||
] {
|
||||
let mut params = params.clone();
|
||||
let mut sandbox = FileSystemSandboxContext::from_permission_profile(
|
||||
PermissionProfile::read_only(),
|
||||
params.cwd.clone(),
|
||||
);
|
||||
sandbox.sandbox_override = sandbox_override;
|
||||
params.sandbox = Some(sandbox);
|
||||
let mut json = serde_json::to_value(¶ms).expect("serialize sandboxed exec");
|
||||
assert_eq!(
|
||||
json["sandbox"].get("sandboxOverride").is_none(),
|
||||
sandbox_override.is_no_override(),
|
||||
);
|
||||
let wire: WireExecParams = serde_json::from_value(json.clone()).expect("wire exec");
|
||||
assert_eq!(ExecParams::from(wire), params);
|
||||
|
||||
json["sandbox"]
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.remove("sandboxOverride");
|
||||
params.sandbox.as_mut().unwrap().sandbox_override = SandboxOverride::NoOverride;
|
||||
let legacy: WireExecParams = serde_json::from_value(json).expect("legacy wire exec");
|
||||
assert_eq!(ExecParams::from(legacy), params);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1779,6 +1810,7 @@ mod tests {
|
||||
let workspace = PathUri::parse("file:///workspace/other").expect("selected workspace");
|
||||
let path = cwd.join("note.txt").expect("read path");
|
||||
let sandbox = FileSystemSandboxContext {
|
||||
sandbox_override: SandboxOverride::EscalatedSandboxWithRestrictions,
|
||||
workspace_roots: vec![workspace],
|
||||
..FileSystemSandboxContext::from_permission_profile(PermissionProfile::Disabled, cwd)
|
||||
};
|
||||
|
||||
@@ -182,7 +182,7 @@ impl FileSystemSandboxRunner {
|
||||
managed_network: None,
|
||||
additional_permissions: None,
|
||||
};
|
||||
sandbox_manager
|
||||
let mut request = sandbox_manager
|
||||
.transform_for_direct_spawn(SandboxDirectSpawnTransformRequest {
|
||||
workspace_roots,
|
||||
windows_sandbox_proxy_settings_mode:
|
||||
@@ -205,7 +205,9 @@ impl FileSystemSandboxRunner {
|
||||
.unwrap_or(WindowsSandboxLevel::Disabled),
|
||||
},
|
||||
})
|
||||
.map_err(|err| invalid_request(format!("failed to prepare fs sandbox: {err}")))
|
||||
.map_err(|err| invalid_request(format!("failed to prepare fs sandbox: {err}")))?;
|
||||
request.sandbox_override = sandbox_context.sandbox_override;
|
||||
Ok(request)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,6 +569,7 @@ mod windows_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsString;
|
||||
|
||||
@@ -809,8 +812,9 @@ mod tests {
|
||||
FileSystemSpecialPath::Root,
|
||||
FileSystemAccessMode::Read,
|
||||
)]);
|
||||
let sandbox_context =
|
||||
let mut sandbox_context =
|
||||
sandbox_context_with_cwd(&policy, PathUri::from_abs_path(&selected_cwd));
|
||||
sandbox_context.sandbox_override = SandboxOverride::EscalatedSandboxWithRestrictions;
|
||||
#[cfg(windows)]
|
||||
let sandbox_context = crate::FileSystemSandboxContext {
|
||||
windows_sandbox_selection: codex_file_system::WindowsSandboxSelection::RestrictedToken,
|
||||
@@ -823,10 +827,15 @@ mod tests {
|
||||
.expect("sandbox command");
|
||||
|
||||
assert_eq!(
|
||||
(request.cwd, request.sandbox_policy_cwd),
|
||||
(
|
||||
request.cwd,
|
||||
request.sandbox_policy_cwd,
|
||||
request.sandbox_override
|
||||
),
|
||||
(
|
||||
PathUri::from_abs_path(&root),
|
||||
PathUri::from_abs_path(&selected_cwd)
|
||||
PathUri::from_abs_path(&selected_cwd),
|
||||
SandboxOverride::EscalatedSandboxWithRestrictions,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
#[cfg(windows)]
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
#[cfg(windows)]
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
#[cfg(windows)]
|
||||
use codex_sandboxing::SandboxExecRequest;
|
||||
#[cfg(windows)]
|
||||
use codex_sandboxing::SandboxType;
|
||||
@@ -231,6 +233,7 @@ fn powershell_command(script: &str, path: &Path) -> anyhow::Result<SandboxExecRe
|
||||
let cwd = PathUri::from_host_native_path(std::env::current_dir()?)?;
|
||||
|
||||
Ok(SandboxExecRequest {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
command: vec![
|
||||
powershell.to_string_lossy().into_owned(),
|
||||
"-NoProfile".to_string(),
|
||||
|
||||
@@ -297,6 +297,7 @@ pub(crate) async fn prepare_exec_request_with_telemetry(
|
||||
sandbox_manager.transform_for_direct_spawn(transform_request)
|
||||
}
|
||||
.map_err(|err| invalid_params(format!("failed to prepare process sandbox: {err}")))?;
|
||||
request.sandbox_override = sandbox_context.sandbox_override;
|
||||
let windows_sandbox = if sandbox == SandboxType::WindowsRestrictedToken {
|
||||
let windows_sandbox_level = windows_sandbox_level.ok_or_else(|| {
|
||||
invalid_params("restricted token sandbox requires a sandbox level".to_string())
|
||||
|
||||
@@ -17,6 +17,7 @@ use codex_protocol::permissions::FileSystemSandboxPolicyContext;
|
||||
use codex_protocol::permissions::FileSystemSpecialPath;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
use codex_utils_path_uri::LegacyAppPathString;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
pub use environment_accessor::EnvironmentAccess;
|
||||
@@ -351,6 +352,9 @@ pub struct FileSystemSandboxContext {
|
||||
/// Serializes paths as executor file URIs instead of the profile's default native paths.
|
||||
#[serde(with = "exec_permission_profile_serde")]
|
||||
pub permissions: PermissionProfile,
|
||||
/// Controller-selected override for observations, never an authorization to widen permissions.
|
||||
#[serde(default, skip_serializing_if = "SandboxOverride::is_no_override")]
|
||||
pub sandbox_override: SandboxOverride,
|
||||
/// Working directory on the selected executor used to interpret sandbox permissions.
|
||||
/// Required even for absolute permissions; a process may use a different working directory.
|
||||
pub cwd: PathUri,
|
||||
@@ -394,6 +398,7 @@ impl FileSystemSandboxContext {
|
||||
pub fn from_permission_profile(permissions: PermissionProfile, cwd: PathUri) -> Self {
|
||||
Self {
|
||||
permissions,
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
workspace_roots: vec![cwd.clone()],
|
||||
cwd,
|
||||
user_home_dir: None,
|
||||
@@ -463,6 +468,8 @@ impl FileSystemSandboxContext {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct WireFileSystemSandboxContext {
|
||||
permissions: ExecPermissionProfile,
|
||||
#[serde(default, skip_serializing_if = "SandboxOverride::is_no_override")]
|
||||
sandbox_override: SandboxOverride,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
cwd: Option<PathUri>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
@@ -495,6 +502,7 @@ impl From<FileSystemSandboxContext> for WireFileSystemSandboxContext {
|
||||
fn from(sandbox: FileSystemSandboxContext) -> Self {
|
||||
let FileSystemSandboxContext {
|
||||
permissions,
|
||||
sandbox_override,
|
||||
cwd,
|
||||
workspace_roots,
|
||||
user_home_dir,
|
||||
@@ -531,6 +539,7 @@ impl From<FileSystemSandboxContext> for WireFileSystemSandboxContext {
|
||||
};
|
||||
Self {
|
||||
permissions,
|
||||
sandbox_override,
|
||||
cwd: legacy_needs_cwd.then(|| cwd.clone()),
|
||||
workspace_roots: if legacy_needs_cwd {
|
||||
workspace_roots.clone()
|
||||
@@ -582,6 +591,7 @@ impl WireFileSystemSandboxContext {
|
||||
pub fn into_context(self, cwd: PathUri) -> FileSystemSandboxContext {
|
||||
FileSystemSandboxContext {
|
||||
permissions: self.permissions.into(),
|
||||
sandbox_override: self.sandbox_override,
|
||||
cwd,
|
||||
workspace_roots: match self.policy_context {
|
||||
Some(policy_context) => policy_context.workspace_roots,
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
//! Identifies the platform sandbox implementation selected for execution.
|
||||
//! Identifies the sandbox implementation and overrides selected for a command.
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::config_types::WindowsSandboxLevel;
|
||||
|
||||
/// Controller decision that overrides normal sandbox selection for a command.
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Eq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum SandboxOverride {
|
||||
/// Use normal sandbox selection.
|
||||
#[default]
|
||||
NoOverride,
|
||||
/// Broaden approved filesystem access while retaining denied-read enforcement.
|
||||
EscalatedSandboxWithRestrictions,
|
||||
/// Bypass the sandbox on the first attempt.
|
||||
BypassSandboxFirstAttempt,
|
||||
}
|
||||
|
||||
impl SandboxOverride {
|
||||
pub fn is_no_override(&self) -> bool {
|
||||
*self == Self::NoOverride
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum SandboxType {
|
||||
|
||||
@@ -23,6 +23,7 @@ use codex_protocol::models::PermissionProfile;
|
||||
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_protocol::sandbox::SandboxOverride;
|
||||
pub use codex_protocol::sandbox::SandboxType;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
@@ -99,6 +100,8 @@ pub struct SandboxCommand {
|
||||
/// conversion to native paths until this request is created.
|
||||
#[derive(Debug)]
|
||||
pub struct SandboxExecRequest {
|
||||
/// Controller-selected override, retained for observations without altering the sandbox command.
|
||||
pub sandbox_override: SandboxOverride,
|
||||
pub command: Vec<String>,
|
||||
pub cwd: PathUri,
|
||||
pub sandbox_policy_cwd: PathUri,
|
||||
@@ -548,6 +551,7 @@ impl SandboxManager {
|
||||
});
|
||||
|
||||
Ok(SandboxExecRequest {
|
||||
sandbox_override: SandboxOverride::NoOverride,
|
||||
command: argv,
|
||||
cwd: command.cwd,
|
||||
sandbox_policy_cwd: sandbox_policy_cwd.clone(),
|
||||
|
||||
Reference in New Issue
Block a user