Skip to content

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

test(sandbox): remove local jail and capture tests

Steven Enamakel10a2bc156393
diff --git a/crates/openhuman-core/src/sandbox/ops_tests.rs b/crates/openhuman-core/src/sandbox/ops_tests.rs
index b35f0bc721..3efc2f08eb 100644
--- a/crates/openhuman-core/src/sandbox/ops_tests.rs
+++ b/crates/openhuman-core/src/sandbox/ops_tests.rs
@@ -99,46 +99,6 @@ async fn create_sandbox_backend_none() {
assert_eq!(handle.status, SandboxStatus::Ready);
}
-#[tokio::test]
-async fn create_sandbox_backend_local() {
- let policy = resolve_sandbox_policy(
- SandboxMode::Sandboxed,
- Path::new("/tmp"),
- Path::new("/tmp/state"),
- &RuntimeConfig::default(),
- false,
- );
- let handle = create_sandbox_backend(&policy).await;
- assert_eq!(handle.kind, SandboxBackendKind::Local);
-
- // Assert the BACKEND -> STATUS pairing, not a fixed value. This test
- // previously asserted `Ready` unconditionally, which is precisely the
- // defect being fixed: on a host with no OS jail, `pick_backend` falls back
- // to `NoopBackend` (or TinyBox's `unsupported` backend) and the handle
- // claimed the sandbox was ready while commands ran unconfined. Which branch
- // runs here depends on the CI host, so pin the relationship instead of the
- // outcome.
- let backend_id = handle
- .backend_id
- .as_deref()
- .expect("the local backend must name itself so a caller can tell which jail is in force");
- if backend_id == cwd_jail::NOOP_BACKEND_NAME
- || backend_id == cwd_jail::detect::UNSUPPORTED_BACKEND_NAME
- {
- assert_eq!(
- handle.status,
- SandboxStatus::Inactive,
- "the {backend_id} backend does not enforce a jail, so it must not report `Ready`"
- );
- } else {
- assert_eq!(
- handle.status,
- SandboxStatus::Ready,
- "a real OS jail ({backend_id}) is in force, so `Ready` is honest"
- );
- }
-}
-
// The `/tmp` path and Unix builtins (`false`) are Unix-only, so these
// integration-style tests are gated to Unix. A cross-platform
// `execute_unsandboxed_echo_runs_on_every_os` below exercises the same
@@ -296,34 +256,6 @@ fn env_passthrough_includes_safe_vars() {
);
}
-// ── the security-relevant decision, tested independently of the host ─────────
-//
-// `create_sandbox_backend_local` above can only exercise whichever branch this
-// machine happens to take. On a host with Seatbelt or Landlock it never reaches
-// the noop path, so a regression to "always Ready" would pass there unnoticed —
-// which is how the original defect survived. These pin the decision directly.
-
-#[test]
-fn local_status_is_inactive_when_no_os_jail_is_in_force() {
- assert_eq!(
- local_status_for_backend(cwd_jail::NOOP_BACKEND_NAME),
- SandboxStatus::Inactive,
- "the noop backend enforces nothing; reporting `Ready` tells a caller its \
- commands are jailed when they run unconfined"
- );
-}
-
-#[test]
-fn local_status_is_ready_for_a_real_jail() {
- for backend in ["seatbelt", "landlock", "appcontainer"] {
- assert_eq!(
- local_status_for_backend(backend),
- SandboxStatus::Ready,
- "a real OS jail ({backend}) is in force, so `Ready` is honest"
- );
- }
-}
-
// ── Windows child environment ────────────────────────────────────────────────
//
// `execute_unsandboxed` and `execute_local_jail` both call `env_clear()` and
@@ -341,302 +273,6 @@ fn local_status_is_ready_for_a_real_jail() {
// has to be a Rust `CreateProcess` spawn: `node`'s own `child_process.spawn`
// silently injects `SystemRoot`, so a JavaScript probe reports a stripped
// environment as healthy.
-// ── #6961: local-jail output capture stays out of the user's project ─────────
-
-#[cfg(unix)]
-fn local_policy(action_dir: &Path, state_dir: &Path) -> SandboxPolicy {
- let policy = resolve_sandbox_policy(
- SandboxMode::Sandboxed,
- action_dir,
- state_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 state = tempfile::tempdir().unwrap();
- let policy = local_policy(action.path(), state.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 state = tempfile::tempdir().unwrap();
- let policy = local_policy(action.path(), state.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")
- );
-}
-
-#[cfg(unix)]
-#[tokio::test]
-async fn local_jail_captures_under_the_state_dir_and_removes_the_call_dir() {
- let action = tempfile::tempdir().unwrap();
- let state = tempfile::tempdir().unwrap();
- let mut policy = local_policy(action.path(), state.path());
- let capture_root = sandbox_capture_root(state.path());
- assert_eq!(
- capture_root,
- state.path().join("artifacts").join("sandbox-capture")
- );
- // A real jail grants only the per-call dir, so the command cannot list the
- // capture root on its own; grant it read-only so this test can look.
- std::fs::create_dir_all(&capture_root).unwrap();
- policy.read_only_mounts.push(capture_root.clone());
-
- // While running, exactly one per-call dir holding both streams exists.
- let during = run_local(&policy, &format!("ls '{}'/*", capture_root.display())).await;
- assert!(during.success(), "stderr: {}", during.stderr);
- assert_eq!(during.stdout, "stderr\nstdout\n");
-
- assert!(
- entries(&capture_root).is_empty(),
- "per-call capture dir left behind: {:?}",
- entries(&capture_root)
- );
-}
-
-#[cfg(unix)]
-#[tokio::test]
-async fn local_jail_removes_the_call_dir_when_the_spawn_fails() {
- let cwd = tempfile::tempdir().unwrap();
- let state = tempfile::tempdir().unwrap();
- // A jail root that does not exist makes the jail refuse to spawn.
- let policy = local_policy(&cwd.path().join("missing-root"), state.path());
-
- let err = execute_in_sandbox(
- &policy,
- "true",
- cwd.path(),
- HashMap::new(),
- Duration::from_secs(5),
- )
- .await
- .unwrap_err();
-
- assert!(
- err.to_string().contains("Failed to spawn jailed process"),
- "{err}"
- );
- assert!(entries(&sandbox_capture_root(state.path())).is_empty());
-}
-
-// ── tinybox `unsupported` backend is not a jail ──────────────────────────────
-
-#[test]
-fn local_status_is_inactive_for_the_unsupported_backend() {
- assert_eq!(
- local_status_for_backend(cwd_jail::detect::UNSUPPORTED_BACKEND_NAME),
- SandboxStatus::Inactive,
- "`pick_backend` answers `unsupported` when no OS jail exists and the host then runs \
- commands through the no-op fallback; `Ready` would claim confinement that is absent"
- );
-}
-
-// ── tinybox#23: with a real jail, everyday commands still work ───────────────
-//
-// These run a real Landlock jail and skip (loudly) where the kernel has none,
-// so they never fail a host that cannot confine.
-
-#[cfg(target_os = "linux")]
-fn landlock_in_force() -> bool {
- let backend = cwd_jail::default_backend();
- let ok = backend.name() == "landlock" && backend.is_available();
- if !ok {
- eprintln!(
- "SKIP: no Landlock on this host (backend = {})",
- backend.name()
- );
- }
- ok
-}
-
-#[cfg(target_os = "linux")]
-fn host_has(program: &str) -> bool {
- std::process::Command::new("sh")
- .arg("-c")
- .arg(format!("command -v {program}"))
- .output()
- .map(|o| o.status.success())
- .unwrap_or(false)
-}
-
-#[cfg(target_os = "linux")]
-#[tokio::test]
-async fn landlock_jail_runs_cargo_and_mktemp_but_blocks_writes_outside() {
- if !landlock_in_force() {
- return;
- }
- let action = tempfile::tempdir().unwrap();
- let state = tempfile::tempdir().unwrap();
- let outside = tempfile::tempdir().unwrap();
- let policy = local_policy(action.path(), state.path());
-
- // Cargo records the executable for the active build toolchain. Use it
- // directly so this check exercises Cargo inside the jail: a rustup proxy
- // on PATH can try to initialize a different HOME in a CI container.
- let cargo = Path::new(env!("CARGO"));
- if cargo.is_file() {
- let quoted_cargo = format!("'{}'", cargo.to_string_lossy().replace('\'', "'\\''"));
- let r = run_local(&policy, &format!("{quoted_cargo} --version")).await;
- assert!(r.success(), "cargo failed under the jail: {}", r.stderr);
- assert!(r.stdout.starts_with("cargo "), "stdout: {}", r.stdout);
- } else {
- eprintln!("SKIP cargo: build toolchain executable is absent on this host");
- }
-
- // `/tmp` is not granted; `mktemp` lands in the per-call TMPDIR scratch dir.
- let r = run_local(&policy, "mktemp").await;
- assert!(r.success(), "mktemp failed under the jail: {}", r.stderr);
- assert!(
- r.stdout
- .trim()
- .starts_with(sandbox_scratch_root(state.path()).to_str().unwrap()),
- "mktemp should land in the scratch dir, got {:?}",
- r.stdout
- );
- assert!(
- entries(&sandbox_scratch_root(state.path())).is_empty(),
- "per-call scratch dir left behind"
- );
-
- // The jail still confines: writing outside the root fails.
- let target = outside.path().join("pwned");
- let r = run_local(&policy, &format!("echo x > '{}'", target.display())).await;
- assert!(!r.success(), "write outside the root must fail");
- assert!(!target.exists(), "the jail let a write escape");
-
- // ...while the workspace root itself stays writable.
- let r = run_local(&policy, "echo ok > inside.txt").await;
- assert!(r.success(), "stderr: {}", r.stderr);
- assert!(action.path().join("inside.txt").exists());
-}
-
-#[cfg(target_os = "linux")]
-#[tokio::test]
-async fn landlock_jail_denies_proc_unless_the_toggle_is_on() {
- if !landlock_in_force() {
- return;
- }
- let action = tempfile::tempdir().unwrap();
- let state = tempfile::tempdir().unwrap();
- let policy = local_policy(action.path(), state.path());
- let denied = run_local(&policy, "cat /proc/self/environ > /dev/null").await;
- assert!(!denied.success(), "/proc must be off by default");
-
- let config = RuntimeConfig {
- local_jail: crate::config::LocalJailConfig {
- allow_proc: true,
- ..Default::default()
- },
- ..RuntimeConfig::default()
- };
- let policy = resolve_sandbox_policy(
- SandboxMode::Sandboxed,
- action.path(),
- state.path(),
- &config,
- false,
- );
- let allowed = run_local(&policy, "cat /proc/self/environ > /dev/null").await;
- assert!(allowed.success(), "stderr: {}", allowed.stderr);
-}
-
-#[cfg(target_os = "linux")]
-#[tokio::test]
-async fn landlock_jail_cannot_read_the_users_ssh_directory() {
- if !landlock_in_force() {
- return;
- }
- let Some(ssh) = dirs::home_dir()
- .map(|h| h.join(".ssh"))
- .filter(|p| p.is_dir())
- else {
- eprintln!("SKIP: no ~/.ssh on this host");
- return;
- };
- let action = tempfile::tempdir().unwrap();
- let state = tempfile::tempdir().unwrap();
- let policy = local_policy(action.path(), state.path());
- let r = run_local(&policy, &format!("ls '{}'", ssh.display())).await;
- assert!(!r.success(), "~/.ssh must stay unreachable from the jail");
-}
-
-#[cfg(unix)]
-#[tokio::test]
-async fn local_handle_status_matches_the_backend_actually_in_force() {
- let action = tempfile::tempdir().unwrap();
- let state = tempfile::tempdir().unwrap();
- let handle = create_sandbox_backend(&local_policy(action.path(), state.path())).await;
- let name = handle.backend_id.clone().unwrap();
- let unconfined =
- name == cwd_jail::NOOP_BACKEND_NAME || name == cwd_jail::detect::UNSUPPORTED_BACKEND_NAME;
- assert_eq!(
- handle.status,
- if unconfined {
- SandboxStatus::Inactive
- } else {
- SandboxStatus::Ready
- },
- "backend = {name}"
- );
-}
-
#[test]
fn sandbox_off_value_accepts_off_spellings() {
for v in ["off", "OFF", " none ", "0", "false", "Disabled"] {