Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix: preserve sandbox temp overrides

Steven Enamakel664251659a08
diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rs
index ccf0a7ffa9..2ca9b0de42 100644
--- a/crates/openhuman-core/src/sandbox/ops.rs
+++ b/crates/openhuman-core/src/sandbox/ops.rs
@@ -279,10 +279,10 @@ async fn execute_unsandboxed(
cmd.env(var, val);
}
}
+ platform_shell::forward_windows_bootstrap_env(&mut cmd)?;
for (k, v) in extra_env {
cmd.env(k, v);
}
- platform_shell::forward_windows_bootstrap_env(&mut cmd)?;
let result = tokio::time::timeout(timeout, cmd.output()).await;
match result {
@@ -396,6 +396,9 @@ async fn execute_local_jail(
jail = jail.add_read_write(&scratch.path);
let stdout_file = capture.stdout();
let stderr_file = capture.stderr();
+ let caller_sets_tmpdir = extra_env.contains_key(std::ffi::OsStr::new("TMPDIR"));
+ let caller_sets_temp = extra_env.contains_key(std::ffi::OsStr::new("TEMP"));
+ let caller_sets_tmp = extra_env.contains_key(std::ffi::OsStr::new("TMP"));
// Platform-aware output-capture wrap: `{ … ; } > … 2> …` on sh/bash,
// trailing `> … 2> …` on cmd.exe (no brace grouping). Shell binary is
// picked by `platform_shell` so this path is Windows-safe (#4705).
@@ -411,16 +414,22 @@ async fn execute_local_jail(
cmd.env(var, val);
}
}
+ platform_shell::forward_windows_bootstrap_env_std(&mut cmd)?;
for (k, v) in extra_env {
cmd.env(k, v);
}
- platform_shell::forward_windows_bootstrap_env_std(&mut cmd)?;
// Keep every Windows spelling of the temporary directory inside this
// per-call grant. `TEMP`/`TMP` are the variables used by Windows tools;
// `TMPDIR` covers Unix-oriented tools running on the same host.
- cmd.env("TMPDIR", &scratch.path);
- cmd.env("TEMP", &scratch.path);
- cmd.env("TMP", &scratch.path);
+ if !caller_sets_tmpdir {
+ cmd.env("TMPDIR", &scratch.path);
+ }
+ if !caller_sets_temp {
+ cmd.env("TEMP", &scratch.path);
+ }
+ if !caller_sets_tmp {
+ cmd.env("TMP", &scratch.path);
+ }
let os_backend = cwd_jail::default_backend();
let spawn_result = if os_backend.is_available() {
diff --git a/tests/windows_sandbox_env_e2e.rs b/tests/windows_sandbox_env_e2e.rs
index c93b50f0ae..300254113f 100644
--- a/tests/windows_sandbox_env_e2e.rs
+++ b/tests/windows_sandbox_env_e2e.rs
@@ -40,6 +40,18 @@ async fn run_in_sandbox(
) -> (
openhuman_core::sandbox::types::SandboxExecResult,
std::path::PathBuf,
+) {
+ run_in_sandbox_with_env(mode, command, HashMap::new()).await
+}
+
+#[cfg(windows)]
+async fn run_in_sandbox_with_env(
+ mode: SandboxMode,
+ command: &str,
+ extra_env: HashMap<String, String>,
+) -> (
+ openhuman_core::sandbox::types::SandboxExecResult,
+ std::path::PathBuf,
) {
let tempdir = tempfile::tempdir().expect("tempdir");
let root = tempdir.path().to_path_buf();
@@ -54,7 +66,10 @@ async fn run_in_sandbox(
&policy,
command,
tempdir.path(),
- HashMap::new(),
+ extra_env
+ .into_iter()
+ .map(|(key, value)| (key.into(), value.into()))
+ .collect(),
Duration::from_secs(120),
)
.await
@@ -152,6 +167,35 @@ async fn sandboxed_child_receives_windows_bootstrap_env() {
assert_temp_is_in_scratch(&result, &root);
}
+/// Caller-provided temporary-directory values remain effective on both host
+/// spawn paths; the local jail must not silently replace per-call overrides.
+#[cfg(windows)]
+#[tokio::test]
+async fn caller_temp_overrides_survive_sandbox_paths() {
+ let expected = r"C:\openhuman-test-temp";
+ for mode in [SandboxMode::None, SandboxMode::Sandboxed] {
+ let (result, _) = run_in_sandbox_with_env(
+ mode,
+ "echo TEMP=[%TEMP%] TMP=[%TMP%] TMPDIR=[%TMPDIR%]",
+ HashMap::from([
+ ("TEMP".to_string(), expected.to_string()),
+ ("TMP".to_string(), expected.to_string()),
+ ("TMPDIR".to_string(), expected.to_string()),
+ ]),
+ )
+ .await;
+ assert!(result.success(), "child failed: {:?}", result.stderr);
+ for name in ["TEMP", "TMP", "TMPDIR"] {
+ assert_eq!(
+ bracketed(&result.stdout, &format!("{name}=")).as_deref(),
+ Some(expected),
+ "caller override for {name} was replaced; stdout {:?}",
+ result.stdout
+ );
+ }
+ }
+}
+
/// The reported Node failure, end to end through OpenHuman's spawn code:
/// `node -e` must reach the crypto provider and print random bytes.
#[cfg(windows)]