From db8efdad134c91de730cb2eb3c793555ef6661b4 Mon Sep 17 00:00:00 2001 From: David Wiesen Date: Sat, 21 Mar 2026 10:34:51 -0700 Subject: [PATCH] Skip WindowsApps package dirs in sandbox read roots --- .../src/setup_orchestrator.rs | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs b/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs index 317a4d467c..8e3f937b13 100644 --- a/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs +++ b/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs @@ -287,11 +287,26 @@ fn profile_read_roots(user_profile: &Path) -> Vec { .collect() } +fn is_windowsapps_package_path(path: &Path) -> bool { + path.to_string_lossy() + .to_ascii_lowercase() + .contains(r"\program files\windowsapps\") +} + +fn helper_source_read_root(current_exe: Option<&Path>) -> Option { + let dir = current_exe?.parent()?; + if is_windowsapps_package_path(dir) { + None + } else { + Some(dir.to_path_buf()) + } +} + fn gather_helper_read_roots(codex_home: &Path) -> Vec { let mut roots = Vec::new(); if let Ok(exe) = std::env::current_exe() { - if let Some(dir) = exe.parent() { - roots.push(dir.to_path_buf()); + if let Some(dir) = helper_source_read_root(Some(exe.as_path())) { + roots.push(dir); } } let helper_dir = helper_bin_dir(codex_home); @@ -673,6 +688,7 @@ fn filter_sensitive_write_roots(mut roots: Vec, codex_home: &Path) -> V mod tests { use super::gather_legacy_full_read_roots; use super::gather_read_roots; + use super::helper_source_read_root; use super::profile_read_roots; use super::WINDOWS_PLATFORM_DEFAULT_READ_ROOTS; use crate::helper_materialization::helper_bin_dir; @@ -738,6 +754,31 @@ mod tests { assert!(roots.contains(&expected)); } + #[test] + fn helper_source_read_root_skips_windowsapps_package_dir() { + let current_exe = PathBuf::from( + r"C:\Program Files\WindowsApps\OpenAI.Codex_26.313.5234.0_x64__2p2nqsd0c76g0\app\codex.exe", + ); + + let root = helper_source_read_root(Some(current_exe.as_path())); + + assert_eq!(None, root); + } + + #[test] + fn helper_source_read_root_keeps_non_windowsapps_dir() { + let current_exe = PathBuf::from(r"C:\Users\alice\AppData\Local\Programs\Codex\codex.exe"); + + let root = helper_source_read_root(Some(current_exe.as_path())); + + assert_eq!( + Some(PathBuf::from( + r"C:\Users\alice\AppData\Local\Programs\Codex" + )), + root + ); + } + #[test] fn restricted_read_roots_skip_platform_defaults_when_disabled() { let tmp = TempDir::new().expect("tempdir");