Route filesystem reads and writes by their own sandbox permissions (#46122)

## Why

Filesystem reads previously required a sandbox whenever writes were restricted, even with full-disk read permission. This made permitted reads depend on sandbox availability.

## What changed

- Select sandboxing independently for reads and writes, allowing full-disk reads directly while keeping restricted operations sandboxed.
- Use the executor's path convention when evaluating full-disk access, including `:slash_tmp` denials.
- Apply read-specific checks to capability discovery and skill resource reads, allowing unrestricted reads on executors without sandboxed discovery support.

## Testing

Add regression tests for direct read APIs, restricted writes and reads, executor-specific permission rules, and capability discovery without sandbox support. Update Windows tests to verify sandbox enforcement through writes.

GitOrigin-RevId: a03844bd1f0ea583bb54326683cddbfdd050119f
This commit is contained in:
Adam Perry @ OpenAI authored and copyberry committed 2026-09-17 05:09:03 +00:00
1 parent 70e8fe1be3
commit a4ee536f01
15 files changed
+635 -151

No files matched your search

@@ -236,10 +236,20 @@ async fn file_system_operations_can_reject_junctions_in_any_path_component(
.file_system
.read_file(&uri(&existing)?, no_follow_read, Some(&sandbox))
.await;
if is_unsupported_restricted_token_host(&read_result) {
assert_eq!(read_result?, b"unchanged");
let write_result = context
.file_system
.write_file(
&uri(&existing)?,
b"unchanged".to_vec(),
no_follow_write,
Some(&sandbox),
)
.await;
if is_unsupported_restricted_token_host(&write_result) {
return Ok(());
}
assert_eq!(read_result?, b"unchanged");
write_result?;
assert!(
context
.file_system
@@ -380,6 +390,17 @@ async fn file_system_remote_fs_helper_respects_windows_sandbox_write_policy(
}
}
let readable_file = readonly_dir.join("readable.txt");
std::fs::write(&readable_file, b"readable")?;
let read_result = file_system
.read_file(
&PathUri::from_host_native_path(&readable_file)?,
ReadFileOptions::default(),
Some(&sandbox),
)
.await;
assert_eq!(read_result?, b"readable");
let blocked_file = readonly_dir.join("blocked.txt");
if sandbox_type == SandboxType::WindowsMxc && !codex_sandboxing::windows_mxc_available() {
let error = file_system
@@ -402,34 +423,23 @@ async fn file_system_remote_fs_helper_respects_windows_sandbox_write_policy(
return Ok(());
}
let readable_file = readonly_dir.join("readable.txt");
std::fs::write(&readable_file, b"readable")?;
let read_result = file_system
.read_file(
&PathUri::from_host_native_path(&readable_file)?,
ReadFileOptions::default(),
Some(&sandbox),
)
.await;
// Some local Windows hosts cannot create restricted tokens. Reaching that
// error still proves the remote fs helper went through the Windows sandbox
// launcher; before the wrapper fix this read would have run unsandboxed.
if sandbox_type == SandboxType::WindowsRestrictedToken
&& is_unsupported_restricted_token_host(&read_result)
{
return Ok(());
}
assert_eq!(read_result?, b"readable");
let error = file_system
let write_result = file_system
.write_file(
&PathUri::from_host_native_path(&blocked_file)?,
b"blocked".to_vec(),
WriteFileOptions::default(),
Some(&sandbox),
)
.await
.expect_err("write outside the sandbox should fail");
.await;
// Some local Windows hosts cannot create restricted tokens. Reaching that
// error still proves the write went through the Windows sandbox launcher.
if sandbox_type == SandboxType::WindowsRestrictedToken
&& is_unsupported_restricted_token_host(&write_result)
{
assert!(!blocked_file.exists());
return Ok(());
}
let error = write_result.expect_err("write outside the sandbox should fail");
assert!(
!blocked_file.exists(),
"sandboxed fs helper must not create blocked file after error: {error}"
@@ -562,14 +572,19 @@ async fn file_system_private_desktop_survives_helper_exits_and_separates_permiss
let mut sandbox = workspace_write_sandbox(tmp.path().to_path_buf());
sandbox.windows_sandbox_private_desktop = true;
let before = process_private_desktops()?;
let read = file_system
.read_file(&uri, ReadFileOptions::default(), Some(&sandbox))
let write = file_system
.write_file(
&uri,
b"initial".to_vec(),
WriteFileOptions::default(),
Some(&sandbox),
)
.await;
if is_unsupported_restricted_token_host(&read) {
if is_unsupported_restricted_token_host(&write) {
eprintln!("Skipping private desktop reuse: this host cannot create restricted tokens");
return Ok(());
}
assert_eq!(read?, b"initial");
write?;
// Ownership must outlive each helper; a desktop held only by the helper disappears here.
let warmed = process_private_desktops()?;
@@ -610,15 +625,6 @@ async fn file_system_private_desktop_survives_helper_exits_and_separates_permiss
let mut readonly = read_only_sandbox_for_cwd(tmp.path().to_path_buf())?;
readonly.windows_sandbox_selection = WindowsSandboxSelection::RestrictedToken;
readonly.windows_sandbox_private_desktop = true;
assert_eq!(
file_system
.read_file(&uri, ReadFileOptions::default(), Some(&readonly))
.await?,
b"updated again"
);
let separated = process_private_desktops()?;
assert!(warmed.is_subset(&separated));
assert_eq!(separated.difference(&warmed).count(), 1);
file_system
.write_file(
&uri,
@@ -629,6 +635,15 @@ async fn file_system_private_desktop_survives_helper_exits_and_separates_permiss
.await
.expect_err("read-only filesystem requests must reject writes");
assert_eq!(std::fs::read(&path)?, b"updated again");
let separated = process_private_desktops()?;
assert!(warmed.is_subset(&separated));
assert_eq!(separated.difference(&warmed).count(), 1);
assert_eq!(
file_system
.read_file(&uri, ReadFileOptions::default(), Some(&readonly))
.await?,
b"updated again"
);
assert_eq!(process_private_desktops()?, separated);
Ok(())
}