Skip to content

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

fix(sandbox): allow shell redirection to /dev/null

Steven Enamakele9f1c8733ee9
diff --git a/crates/openhuman-core/src/sandbox/cwd_jail/README.md b/crates/openhuman-core/src/sandbox/cwd_jail/README.md
index 0453c43140..2e8a91ce5f 100644
--- a/crates/openhuman-core/src/sandbox/cwd_jail/README.md
+++ b/crates/openhuman-core/src/sandbox/cwd_jail/README.md
@@ -81,7 +81,7 @@ The Linux backend's docstring references `crate::security::landlock` as conceptu
- **Not RPC-facing, no agent tools, no event bus.** There is no `schemas.rs`, `tools.rs`, or `bus.rs`; the module exposes no `openhuman.*` RPC methods, owns no agent tools, and publishes/subscribes to no `DomainEvent`s.
- **Backends differ in what `allow_net` / `read_only` mean.** Landlock does not gate network at all; macOS Seatbelt grants `allow default` (full network) and treats `read_only` as informational since reads are already allowed; Windows AppContainer is the only backend that honors `read_only` as a real read grant and maps `allow_net` to the strictly outbound-only `internetClient` capability (LAN/inbound capabilities deliberately excluded).
- **Windows `spawn` currently returns an error after a successful launch.** `spawn_in_container` creates the process successfully but cannot bridge the raw `HANDLE` into a `std::process::Child` (the needed `FromRawHandle for Child` is unstable), so it closes the handle and returns `io::ErrorKind::Unsupported`. See the TODO in `windows.rs`. The Windows path is compile-checked but flagged as needing real-hardware testing.
-- **macOS stdio is inherited** — the Seatbelt wrapper cannot re-apply the original command's `Stdio` config; it uses `sandbox-exec` defaults (inherit). The profile re-allows writes only under canonicalized `root` + `/private/tmp`, so callers must canonicalize first (the `spawn` facade does this automatically) or writes inside `root` may be denied (e.g. `/tmp` → `/private/tmp`).
+- **macOS stdio is inherited** — the Seatbelt wrapper cannot re-apply the original command's `Stdio` config; it uses `sandbox-exec` defaults (inherit). The profile re-allows writes under canonicalized `root` and `/private/tmp`, plus the exact `/dev/null` device for shell redirection; it does not grant `/dev` generally. Callers must canonicalize the root first (the `spawn` facade does this automatically) or writes inside it may be denied (e.g. `/tmp` → `/private/tmp`).
- **Linux Landlock runs in `pre_exec`** (child-side after fork) so the parent keeps its privileges; read-only paths also get `Execute` so the child can run binaries found there (e.g. `/usr/bin/sh`).
- **Registry containment guard:** both `delete` and `jail_for` (used by `spawn_in`/`spawn_in_with`) refuse to operate on a record whose canonicalized `dir` is not under the canonicalized `base`, defending against a corrupted index pointing at `/`.
- **Free-form input is length-logged, not value-logged** (labels/notes) to avoid leaking arbitrary text into logs.
diff --git a/crates/openhuman-core/src/sandbox/cwd_jail/macos.rs b/crates/openhuman-core/src/sandbox/cwd_jail/macos.rs
index c970aa558f..87a2d0af0d 100644
--- a/crates/openhuman-core/src/sandbox/cwd_jail/macos.rs
+++ b/crates/openhuman-core/src/sandbox/cwd_jail/macos.rs
@@ -104,10 +104,12 @@ fn render_profile(jail: &Jail) -> String {
// The actual directory jail: deny writes everywhere, then re-allow
// them under root + /private/tmp (the macOS scratchpad most tools
- // assume exists and is writable).
+ // assume exists and is writable). Shell redirections to /dev/null are
+ // ordinary output disposal, not a write to another workspace; permit
+ // that exact device without opening the rest of /dev.
out.push_str("(deny file-write*)\n");
out.push_str(&format!(
- "(allow file-write*\n (subpath \"{}\")\n (subpath \"/private/tmp\")\n)\n",
+ "(allow file-write*\n (subpath \"{}\")\n (subpath \"/private/tmp\")\n (literal \"/dev/null\")\n)\n",
escape(&jail.root.to_string_lossy())
));
diff --git a/crates/openhuman-core/src/sandbox/cwd_jail/macos_tests.rs b/crates/openhuman-core/src/sandbox/cwd_jail/macos_tests.rs
index 0e040b1a07..f78a7398d9 100644
--- a/crates/openhuman-core/src/sandbox/cwd_jail/macos_tests.rs
+++ b/crates/openhuman-core/src/sandbox/cwd_jail/macos_tests.rs
@@ -107,9 +107,44 @@ fn profile_allows_default_and_jails_writes() {
assert!(p.contains("(allow default)"));
assert!(p.contains("(deny file-write*)"));
assert!(p.contains("(subpath \"/tmp/abc\")"));
+ assert!(p.contains("(literal \"/dev/null\")"));
+ assert!(!p.contains("(subpath \"/dev\")"));
assert!(p.contains("(deny network*)"));
}
+#[test]
+fn seatbelt_allows_redirecting_output_to_dev_null() {
+ let backend = SeatbeltBackend::new();
+ if !backend.is_available() {
+ return;
+ }
+ let root = std::env::temp_dir().join(format!("oh-null-{}", std::process::id()));
+ fs::create_dir_all(&root).unwrap();
+ let mut jail = Jail::new(&root, "null-redirection");
+ jail.canonicalize().unwrap();
+
+ let mut cmd = Command::new("/bin/sh");
+ cmd.arg("-c")
+ .arg(
+ "set -e; echo ignored >/dev/null; echo hidden 2>/dev/null >&2; echo completed > output",
+ )
+ .current_dir(&root)
+ .stdout(Stdio::null())
+ .stderr(Stdio::null());
+ let mut child = backend.spawn(&jail, cmd).expect("spawn");
+ let status = child.wait().expect("wait");
+
+ assert!(
+ status.success(),
+ "shell redirection to /dev/null was denied"
+ );
+ assert_eq!(
+ fs::read_to_string(root.join("output")).unwrap(),
+ "completed\n"
+ );
+ fs::remove_dir_all(&root).ok();
+}
+
#[test]
fn seatbelt_spawn_runs_true() {
let backend = SeatbeltBackend::new();