Skip to content

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

fix(sandbox): report the local jail as inactive when nothing is enforcing

M3gA-Mind8a4aac3f369d
diff --git a/src/openhuman/sandbox/cwd_jail/mod.rs b/src/openhuman/sandbox/cwd_jail/mod.rs
index aa959686d4..49756fea61 100644
--- a/src/openhuman/sandbox/cwd_jail/mod.rs
+++ b/src/openhuman/sandbox/cwd_jail/mod.rs
@@ -57,7 +57,7 @@ pub mod macos;
pub mod windows;
pub use jail::{Jail, JailBackend};
-pub use noop::NoopBackend;
+pub use noop::{NoopBackend, NOOP_BACKEND_NAME};
pub use registry::{JailRecord, JailRegistry};
use std::process::{Child, Command};
diff --git a/src/openhuman/sandbox/cwd_jail/noop.rs b/src/openhuman/sandbox/cwd_jail/noop.rs
index a4db3cbe5d..d163c46af0 100644
--- a/src/openhuman/sandbox/cwd_jail/noop.rs
+++ b/src/openhuman/sandbox/cwd_jail/noop.rs
@@ -8,12 +8,21 @@ use std::process::{Child, Command};
use super::jail::{Jail, JailBackend};
+/// The name `NoopBackend` reports, and the value callers compare against to
+/// detect that no OS confinement is in force.
+///
+/// Single-sourced deliberately: `sandbox::ops::create_sandbox_backend` decides
+/// whether the local sandbox handle reports `Ready` or `Inactive` by comparing
+/// against this, so a rename here must not silently turn an unconfined host
+/// back into a `Ready` report.
+pub const NOOP_BACKEND_NAME: &str = "noop";
+
#[derive(Debug, Default)]
pub struct NoopBackend;
impl JailBackend for NoopBackend {
fn name(&self) -> &'static str {
- "noop"
+ NOOP_BACKEND_NAME
}
fn is_available(&self) -> bool {
diff --git a/src/openhuman/sandbox/ops.rs b/src/openhuman/sandbox/ops.rs
index c77168f349..fed0729821 100644
--- a/src/openhuman/sandbox/ops.rs
+++ b/src/openhuman/sandbox/ops.rs
@@ -86,6 +86,25 @@ pub fn resolve_sandbox_policy(
/// Create a backend handle for the resolved policy. For Docker this
/// checks availability; for Local it checks the OS backend.
+/// The status a `Local` sandbox handle reports, given the backend `pick_backend`
+/// actually chose.
+///
+/// Extracted as a free function so the decision is testable on **any** host.
+/// Asserting it through `create_sandbox_backend` cannot work: which branch runs
+/// depends on whether the machine has an OS jail, so on a host with Seatbelt or
+/// Landlock the noop path is never reached and a regression to "always Ready"
+/// passes unnoticed. That is exactly how the original defect survived.
+pub(crate) fn local_status_for_backend(backend_name: &str) -> SandboxStatus {
+ if backend_name == cwd_jail::NOOP_BACKEND_NAME {
+ // The noop backend enforces nothing — it spawns the command as-is. It is
+ // a documented passthrough rather than a failure, so `Inactive`
+ // ("backend not initialized") is the honest report, not `Error`.
+ SandboxStatus::Inactive
+ } else {
+ SandboxStatus::Ready
+ }
+}
+
pub async fn create_sandbox_backend(policy: &SandboxPolicy) -> SandboxBackendHandle {
match policy.backend {
SandboxBackendKind::None => SandboxBackendHandle {
@@ -95,18 +114,36 @@ pub async fn create_sandbox_backend(policy: &SandboxPolicy) -> SandboxBackendHan
},
SandboxBackendKind::Local => {
let os_backend = cwd_jail::default_backend();
+ let backend_name = os_backend.name();
+ // Derive the status from WHICH backend was chosen, not from
+ // `is_available()`.
+ //
+ // `default_backend()` is `cwd_jail::detect::pick_backend`, which
+ // already performs the availability check and substitutes
+ // `NoopBackend` when no OS jail is usable. `NoopBackend::is_available()`
+ // is unconditionally `true` — pinned as a contract by the #3235
+ // regression test — so asking it here always answered `true` and the
+ // `else` arm was unreachable. The handle therefore reported `Ready`
+ // on a host with no confinement at all, which is the one direction a
+ // sandbox status must never be wrong in: a caller that trusts it
+ // believes commands are jailed when they run unconfined.
+ //
+ // The noop backend is a documented passthrough, not a failure, so
+ // `Inactive` ("backend not initialized") is the honest report rather
+ // than `Error`. `backend_id` still carries the name for a caller that
+ // wants the specific backend.
+ let status = local_status_for_backend(backend_name);
+ if status == SandboxStatus::Inactive {
+ tracing::warn!(
+ backend = backend_name,
+ "[sandbox:local] no OS jail available; commands run UNCONFINED and \
+ the handle reports inactive"
+ );
+ }
SandboxBackendHandle {
kind: SandboxBackendKind::Local,
- status: if os_backend.is_available() {
- SandboxStatus::Ready
- } else {
- tracing::warn!(
- backend = os_backend.name(),
- "[sandbox:local] OS jail backend not available, falling back to noop"
- );
- SandboxStatus::Ready
- },
- backend_id: Some(os_backend.name().to_string()),
+ status,
+ backend_id: Some(backend_name.to_string()),
}
}
SandboxBackendKind::Docker => docker::docker_backend_handle().await,
diff --git a/src/openhuman/sandbox/ops_tests.rs b/src/openhuman/sandbox/ops_tests.rs
index df31671cd4..338ac6366e 100644
--- a/src/openhuman/sandbox/ops_tests.rs
+++ b/src/openhuman/sandbox/ops_tests.rs
@@ -103,7 +103,30 @@ async fn create_sandbox_backend_local() {
);
let handle = create_sandbox_backend(&policy).await;
assert_eq!(handle.kind, SandboxBackendKind::Local);
- assert_eq!(handle.status, SandboxStatus::Ready);
+
+ // 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` 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 {
+ assert_eq!(
+ handle.status,
+ SandboxStatus::Inactive,
+ "the noop passthrough enforces nothing, 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
@@ -257,3 +280,31 @@ fn env_passthrough_includes_safe_vars() {
.iter()
.any(|v| v.contains("KEY") || v.contains("SECRET")));
}
+
+// ── 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"
+ );
+ }
+}