Skip to content

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

test(sandbox): add tests for local jail output isolation

Steven Enamakel0443fbc1cbb8
diff --git a/crates/openhuman-core/src/sandbox/ops_tests.rs b/crates/openhuman-core/src/sandbox/ops_tests.rs
index 50c67ae1f4..64b615a4b7 100644
--- a/crates/openhuman-core/src/sandbox/ops_tests.rs
+++ b/crates/openhuman-core/src/sandbox/ops_tests.rs
@@ -308,3 +308,73 @@ fn local_status_is_ready_for_a_real_jail() {
);
}
}
+
+// ── #6961: local-jail output capture stays out of the user's project ─────────
+
+#[cfg(unix)]
+fn local_policy(action_dir: &Path) -> SandboxPolicy {
+ let policy = resolve_sandbox_policy(
+ SandboxMode::Sandboxed,
+ action_dir,
+ &RuntimeConfig::default(),
+ false,
+ );
+ assert_eq!(policy.backend, SandboxBackendKind::Local);
+ policy
+}
+
+#[cfg(unix)]
+async fn run_local(policy: &SandboxPolicy, command: &str) -> SandboxExecResult {
+ execute_in_sandbox(
+ policy,
+ command,
+ &policy.workspace_root,
+ HashMap::new(),
+ Duration::from_secs(20),
+ )
+ .await
+ .unwrap()
+}
+
+#[cfg(unix)]
+fn entries(dir: &Path) -> Vec<String> {
+ let mut names: Vec<String> = std::fs::read_dir(dir)
+ .map(|rd| {
+ rd.map(|e| e.unwrap().file_name().to_string_lossy().into_owned())
+ .collect()
+ })
+ .unwrap_or_default();
+ names.sort();
+ names
+}
+
+#[cfg(unix)]
+#[tokio::test]
+async fn local_jail_writes_no_capture_files_into_the_workspace_root() {
+ let action = tempfile::tempdir().unwrap();
+ let policy = local_policy(action.path());
+
+ // `ls -A` runs inside the root while the capture is live, so it sees
+ // anything the capture put there (this is what `git status` saw).
+ let during = run_local(&policy, "ls -A; echo to-stderr >&2").await;
+
+ assert!(during.success(), "stderr: {}", during.stderr);
+ assert_eq!(during.stdout, "", "root was not empty while running");
+ assert_eq!(during.stderr, "to-stderr\n");
+ assert!(entries(action.path()).is_empty(), "root was not empty after");
+}
+
+#[cfg(unix)]
+#[tokio::test]
+async fn concurrent_local_jail_runs_keep_their_outputs_separate() {
+ let action = tempfile::tempdir().unwrap();
+ let policy = local_policy(action.path());
+
+ let (a, b) = tokio::join!(
+ run_local(&policy, "echo a1; echo a-err >&2; sleep 0.4; echo a2"),
+ run_local(&policy, "echo b1; echo b-err >&2; sleep 0.4; echo b2"),
+ );
+
+ assert_eq!((a.stdout.as_str(), a.stderr.as_str()), ("a1\na2\n", "a-err\n"));
+ assert_eq!((b.stdout.as_str(), b.stderr.as_str()), ("b1\nb2\n", "b-err\n"));
+}