diff --git a/codex-rs/exec-server/src/fs_sandbox.rs b/codex-rs/exec-server/src/fs_sandbox.rs index c695a5dd08..65d8f03db6 100644 --- a/codex-rs/exec-server/src/fs_sandbox.rs +++ b/codex-rs/exec-server/src/fs_sandbox.rs @@ -85,7 +85,7 @@ impl FileSystemSandboxRunner { &file_system_policy, network_policy, ); - let command = self.sandbox_exec_request(&permission_profile, &cwd.uri, sandbox)?; + let command = self.sandbox_exec_request(&permission_profile, &cwd, sandbox)?; let request_json = serde_json::to_vec(&request).map_err(json_error)?; run_command(command, request_json).await } @@ -93,7 +93,7 @@ impl FileSystemSandboxRunner { fn sandbox_exec_request( &self, permission_profile: &PermissionProfile, - cwd: &PathUri, + cwd: &SandboxCwd, sandbox_context: &FileSystemSandboxContext, ) -> Result { let helper = &self.runtime_paths.codex_self_exe; @@ -109,7 +109,7 @@ impl FileSystemSandboxRunner { let command = SandboxCommand { program: helper.as_path().as_os_str().to_owned(), args: vec![CODEX_FS_HELPER_ARG1.to_string()], - cwd: cwd.clone(), + cwd: cwd.uri.clone(), env: self.helper_env.clone(), additional_permissions: None, }; @@ -127,7 +127,7 @@ impl FileSystemSandboxRunner { sandbox, enforce_managed_network: false, network: None, - sandbox_policy_cwd: cwd.as_path(), + sandbox_policy_cwd: &cwd.uri, codex_linux_sandbox_exe: self.runtime_paths.codex_linux_sandbox_exe.as_deref(), use_legacy_landlock: sandbox_context.use_legacy_landlock, windows_sandbox_level: sandbox_context.windows_sandbox_level, @@ -526,15 +526,21 @@ mod tests { let runner = FileSystemSandboxRunner::new(runtime_paths); let native_cwd = AbsolutePathBuf::current_dir().expect("cwd"); let cwd = PathUri::from_abs_path(&native_cwd); - let file_system_policy = - restricted_policy(vec![path_entry(native_cwd, FileSystemAccessMode::Write)]); + let file_system_policy = restricted_policy(vec![path_entry( + native_cwd.clone(), + FileSystemAccessMode::Write, + )]); let network_policy = NetworkSandboxPolicy::Restricted; let permission_profile = PermissionProfile::from_runtime_permissions(&file_system_policy, network_policy); let sandbox_context = sandbox_context_with_cwd(&file_system_policy, cwd.clone()); + let sandbox_cwd = SandboxCwd { + uri: cwd, + native: native_cwd, + }; let request = runner - .sandbox_exec_request(&permission_profile, &cwd, &sandbox_context) + .sandbox_exec_request(&permission_profile, &sandbox_cwd, &sandbox_context) .expect("sandbox exec request"); assert_eq!(request.env.get(&path_key), Some(&path)); diff --git a/codex-rs/sandboxing/src/manager_tests.rs b/codex-rs/sandboxing/src/manager_tests.rs index 5fdc508723..02184c6f30 100644 --- a/codex-rs/sandboxing/src/manager_tests.rs +++ b/codex-rs/sandboxing/src/manager_tests.rs @@ -488,10 +488,11 @@ fn transform_for_direct_spawn_windows_materializes_inner_helper() { let configured_helper = helper_dir.path().join("configured-codex-helper.exe"); std::fs::write(&configured_helper, b"helper").expect("write configured helper"); let cwd = AbsolutePathBuf::from_absolute_path(helper_dir.path()).expect("absolute cwd"); + let cwd_uri = PathUri::from_abs_path(&cwd).expect("cwd URI"); let other_workspace = tempfile::TempDir::new().expect("other workspace"); let other_workspace_root = AbsolutePathBuf::from_absolute_path(other_workspace.path()) .expect("absolute other workspace"); - let workspace_roots = vec![cwd.clone(), other_workspace_root]; + let workspace_roots = vec![cwd, other_workspace_root]; let manager = SandboxManager::new(); let exec_request = manager .transform_for_direct_spawn(SandboxDirectSpawnTransformRequest { @@ -500,7 +501,7 @@ fn transform_for_direct_spawn_windows_materializes_inner_helper() { command: SandboxCommand { program: configured_helper.as_os_str().to_owned(), args: vec!["--codex-run-as-fs-helper".to_string()], - cwd: cwd.clone(), + cwd: cwd_uri.clone(), env: HashMap::from([("Path".to_string(), r"C:\Windows\System32".to_string())]), additional_permissions: None, }, @@ -508,7 +509,7 @@ fn transform_for_direct_spawn_windows_materializes_inner_helper() { sandbox: SandboxType::WindowsRestrictedToken, enforce_managed_network: false, network: None, - sandbox_policy_cwd: cwd.as_path(), + sandbox_policy_cwd: &cwd_uri, codex_linux_sandbox_exe: None, use_legacy_landlock: false, windows_sandbox_level: WindowsSandboxLevel::RestrictedToken,