Compare commits

...

1 Commits

Author SHA1 Message Date
David Wiesen
9d2bb63450 fix(windows): materialize sandbox helpers during setup 2026-05-11 09:12:58 -07:00
4 changed files with 64 additions and 0 deletions

View File

@@ -117,6 +117,44 @@ pub fn resolve_current_exe_for_launch(
}
}
pub fn materialize_setup_dependencies(
codex_home: &Path,
log_dir: Option<&Path>,
) -> Result<Vec<PathBuf>> {
let mut materialized = Vec::new();
let source = std::env::current_exe().context("resolve current executable for setup copy")?;
let file_name = source.file_name().ok_or_else(|| {
anyhow!(
"current executable has no file name for setup copy: {}",
source.display()
)
})?;
let destination = helper_bin_dir(codex_home).join(file_name);
let outcome = copy_from_source_if_needed(&source, &destination)?;
let action = match outcome {
CopyOutcome::Reused => "reused",
CopyOutcome::ReCopied => "recopied",
};
log_note(
&format!(
"helper copy: {action} setup-helper source={} destination={}",
source.display(),
destination.display()
),
log_dir,
);
materialized.push(destination);
materialized.push(copy_helper_if_needed(
HelperExecutable::CommandRunner,
codex_home,
log_dir,
)?);
Ok(materialized)
}
pub(crate) fn copy_helper_if_needed(
kind: HelperExecutable,
codex_home: &Path,

View File

@@ -113,6 +113,8 @@ pub use elevated_impl::run_windows_sandbox_capture as run_windows_sandbox_captur
#[cfg(target_os = "windows")]
pub use helper_materialization::resolve_current_exe_for_launch;
#[cfg(target_os = "windows")]
pub use helper_materialization::materialize_setup_dependencies;
#[cfg(target_os = "windows")]
pub use hide_users::hide_current_user_profile_dir;
#[cfg(target_os = "windows")]
pub use hide_users::hide_newly_created_users;

View File

@@ -62,6 +62,8 @@ pub enum SetupErrorCode {
HelperFirewallRuleVerifyFailed,
/// Helper failed to spawn the read-ACL helper process.
HelperReadAclHelperSpawnFailed,
/// Helper failed to pre-populate `.sandbox-bin` with required executables.
HelperDependencyMaterializationFailed,
/// Helper failed to lock down sandbox directories via ACLs.
HelperSandboxLockFailed,
/// Helper failed for an unmapped or unexpected reason.
@@ -96,6 +98,9 @@ impl SetupErrorCode {
}
Self::HelperFirewallRuleVerifyFailed => "helper_firewall_rule_verify_failed",
Self::HelperReadAclHelperSpawnFailed => "helper_read_acl_helper_spawn_failed",
Self::HelperDependencyMaterializationFailed => {
"helper_dependency_materialization_failed"
}
Self::HelperSandboxLockFailed => "helper_sandbox_lock_failed",
Self::HelperUnknownError => "helper_unknown_error",
}

View File

@@ -23,6 +23,7 @@ use codex_windows_sandbox::install_wfp_filters;
use codex_windows_sandbox::is_command_cwd_root;
use codex_windows_sandbox::load_or_create_cap_sids;
use codex_windows_sandbox::log_note;
use codex_windows_sandbox::materialize_setup_dependencies;
use codex_windows_sandbox::path_mask_allows;
use codex_windows_sandbox::sandbox_bin_dir;
use codex_windows_sandbox::sandbox_dir;
@@ -886,6 +887,24 @@ fn run_setup_full(payload: &Payload, log: &mut File, sbx_dir: &Path) -> Result<(
if legacy_users.exists() {
let _ = std::fs::remove_file(&legacy_users);
}
let materialized = materialize_setup_dependencies(&payload.codex_home, Some(sbx_dir))
.map_err(|err| {
anyhow::Error::new(SetupFailure::new(
SetupErrorCode::HelperDependencyMaterializationFailed,
format!(
"materialize sandbox helper executables into {} failed: {err:#}",
sandbox_bin_dir(&payload.codex_home).display()
),
))
})?;
log_line(
log,
&format!(
"materialized {} helper executable(s) into {}",
materialized.len(),
sandbox_bin_dir(&payload.codex_home).display()
),
)?;
}
unsafe {