mirror of
https://github.com/openai/codex.git
synced 2026-11-08 20:40:33 +00:00
Centralize Windows sandbox filesystem override resolution (#60042)
Add `WindowsSandboxFilesystemOverrides::resolve` to select the elevated or restricted-token resolver, and use it in core, exec-server, and direct-spawn sandbox preparation. Pass the child environment through to the elevated resolver. Replace the exported unsupported-sandbox reason helper with a test-local wrapper around the shared resolver. GitOrigin-RevId: f1d404356a4f680ce81123bc8284508f27d4d6ab
This commit is contained in:
@@ -49,8 +49,6 @@ use codex_sandboxing::record_filesystem_sandbox_violation;
|
||||
use codex_sandboxing::resolve_windows_elevated_filesystem_overrides;
|
||||
#[cfg(test)]
|
||||
use codex_sandboxing::resolve_windows_restricted_token_filesystem_overrides;
|
||||
#[cfg(test)]
|
||||
use codex_sandboxing::unsupported_windows_restricted_token_sandbox_reason;
|
||||
#[cfg(any(test, target_os = "windows"))]
|
||||
use codex_sandboxing::windows_sandbox_uses_elevated_backend;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
|
||||
@@ -556,6 +556,22 @@ fn windows_sandbox_backend_honors_unelevated_configuration() {
|
||||
));
|
||||
}
|
||||
|
||||
fn unsupported_windows_restricted_token_sandbox_reason(
|
||||
sandbox: SandboxType,
|
||||
permission_profile: &PermissionProfile,
|
||||
sandbox_policy_cwd: &AbsolutePathBuf,
|
||||
windows_sandbox_level: WindowsSandboxLevel,
|
||||
) -> Option<String> {
|
||||
WindowsSandboxFilesystemOverrides::resolve(
|
||||
sandbox,
|
||||
permission_profile,
|
||||
sandbox_policy_cwd,
|
||||
windows_sandbox_level,
|
||||
&HashMap::new(),
|
||||
)
|
||||
.err()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_restricted_token_rejects_network_only_restrictions() {
|
||||
let permission_profile = PermissionProfile::from_runtime_permissions(
|
||||
|
||||
@@ -26,9 +26,6 @@ pub use codex_protocol::models::SandboxPermissions;
|
||||
use codex_sandboxing::SandboxExecRequest;
|
||||
use codex_sandboxing::SandboxType;
|
||||
use codex_sandboxing::WindowsSandboxFilesystemOverrides;
|
||||
use codex_sandboxing::resolve_windows_elevated_filesystem_overrides;
|
||||
use codex_sandboxing::resolve_windows_restricted_token_filesystem_overrides;
|
||||
use codex_sandboxing::windows_sandbox_uses_elevated_backend;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use codex_utils_string::truncate_middle_with_token_budget;
|
||||
@@ -142,24 +139,13 @@ impl ExecRequest {
|
||||
let sandbox_policy_cwd = windows_sandbox_policy_cwd
|
||||
.to_abs_path()
|
||||
.map_err(|err| CodexErr::InvalidRequest(format!("invalid sandbox cwd: {err}")))?;
|
||||
let use_windows_elevated_backend =
|
||||
windows_sandbox_uses_elevated_backend(windows_sandbox_level);
|
||||
if use_windows_elevated_backend {
|
||||
resolve_windows_elevated_filesystem_overrides(
|
||||
sandbox,
|
||||
&permission_profile,
|
||||
&sandbox_policy_cwd,
|
||||
use_windows_elevated_backend,
|
||||
&env,
|
||||
)
|
||||
} else {
|
||||
resolve_windows_restricted_token_filesystem_overrides(
|
||||
sandbox,
|
||||
&permission_profile,
|
||||
&sandbox_policy_cwd,
|
||||
windows_sandbox_level,
|
||||
)
|
||||
}
|
||||
WindowsSandboxFilesystemOverrides::resolve(
|
||||
sandbox,
|
||||
&permission_profile,
|
||||
&sandbox_policy_cwd,
|
||||
windows_sandbox_level,
|
||||
&env,
|
||||
)
|
||||
.map_err(|error| {
|
||||
CodexErr::UnsupportedOperation(
|
||||
truncate_middle_with_token_budget(&error, /*max_tokens*/ 900).0,
|
||||
|
||||
Reference in New Issue
Block a user