Skip to content

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

fix(sandbox): report backend error instead of docker handle on fallback

Steven Enamakel70e2acce32b3
diff --git a/crates/openhuman-core/src/sandbox/native_jail.rs b/crates/openhuman-core/src/sandbox/native_jail.rs
index d1a8995411..5c7845bc8e 100644
--- a/crates/openhuman-core/src/sandbox/native_jail.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail.rs
@@ -1,11 +1,9 @@
//! Host policy and lifecycle for TinyBox-owned native jailed executions.
-use std::{
- collections::{BTreeMap, HashMap},
- ffi::{OsStr, OsString},
- path::Path,
- time::Duration,
-};
+use std::{collections::HashMap, ffi::OsString, path::Path, time::Duration};
+
+#[cfg(feature = "modules")]
+use std::{collections::BTreeMap, ffi::OsStr};
use super::types::{SandboxExecResult, SandboxPolicy, SandboxStatus};
use crate::{agent::platform_shell, config::Config};
@@ -17,14 +15,9 @@ use crate::modules::tinybox::{self, contract};
#[cfg(feature = "modules")]
pub(crate) async fn status(config: &Config) -> Result<(String, SandboxStatus), String> {
let status = tinybox::jail_status(config).await?;
- let ready = status.available && status.suitable_for_untrusted_code;
Ok((
status.backend,
- if ready {
- SandboxStatus::Ready
- } else {
- SandboxStatus::Inactive
- },
+ super::ops::local_status_for_jail(status.available, status.suitable_for_untrusted_code),
))
}
diff --git a/crates/openhuman-core/src/sandbox/native_jail_tests.rs b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
index e0fff64044..35e4a51754 100644
--- a/crates/openhuman-core/src/sandbox/native_jail_tests.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
@@ -1,6 +1,7 @@
//! Host-side request mapping for TinyBox native-jail execution.
use super::*;
+#[cfg(all(feature = "modules", target_os = "linux"))]
use std::path::PathBuf;
#[test]
@@ -105,6 +106,41 @@ fn native_jail_environment_keeps_the_sandbox_allowlist_and_scratch_grant() -> an
Ok(())
}
+#[cfg(feature = "modules")]
+#[tokio::test]
+async fn disabled_tinybox_module_never_falls_back_to_host_execution() -> anyhow::Result<()> {
+ let workspace = tempfile::tempdir()?;
+ let state = tempfile::tempdir()?;
+ let marker = workspace.path().join("must-not-run");
+ let policy = SandboxPolicy {
+ backend: super::super::types::SandboxBackendKind::Local,
+ workspace_root: workspace.path().to_path_buf(),
+ state_dir: state.path().to_path_buf(),
+ read_only_mounts: Vec::new(),
+ read_write_mounts: Vec::new(),
+ allow_network: true,
+ env_passthrough: Vec::new(),
+ docker_overrides: None,
+ };
+ let mut config = crate::config::Config::default();
+ config.modules.enabled = false;
+
+ let result = execute(
+ &config,
+ &policy,
+ &format!("touch '{}'", marker.display()),
+ workspace.path(),
+ &HashMap::new(),
+ Duration::from_secs(5),
+ false,
+ )
+ .await;
+
+ assert!(result.is_err(), "native jail must refuse without TinyBox");
+ assert!(!marker.exists(), "refusal must never run the host command");
+ Ok(())
+}
+
#[cfg(all(feature = "modules", target_os = "linux"))]
struct BundledModulesRestore(Option<OsString>);
@@ -196,7 +232,7 @@ async fn released_tinybox_runs_a_native_jail_through_the_pinned_loader() -> anyh
let output = execute(
&config,
&policy,
- "i=0; while [ \\"$i\\" -lt 1500 ]; do printf 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; i=$((i + 1)); done",
+ "i=0; while [ $i -lt 1500 ]; do printf 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; i=$((i + 1)); done",
workspace.path(),
&HashMap::new(),
Duration::from_secs(10),
diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rs
index 3da64f5386..40c874af3a 100644
--- a/crates/openhuman-core/src/sandbox/ops.rs
+++ b/crates/openhuman-core/src/sandbox/ops.rs
@@ -211,6 +211,7 @@ pub fn resolve_sandbox_policy(
/// 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.
+#[cfg(any(feature = "modules", test))]
pub(crate) fn local_status_for_jail(
available: bool,
suitable_for_untrusted_code: bool,
@@ -226,7 +227,11 @@ pub async fn create_sandbox_backend(policy: &SandboxPolicy) -> SandboxBackendHan
if policy.backend != SandboxBackendKind::Docker {
return create_sandbox_backend_with_config(policy, &crate::config::Config::default())
.await
- .unwrap_or_else(|_| docker_error_handle());
+ .unwrap_or_else(|_| SandboxBackendHandle {
+ kind: policy.backend,
+ status: SandboxStatus::Error,
+ backend_id: None,
+ });
}
let config = match crate::config::ops::load_config_with_timeout().await {
Ok(config) => config,
@@ -470,16 +475,19 @@ async fn execute_unsandboxed(
}
/// Where module-owned native jailed executions create a per-call writable scratch area.
+#[cfg(feature = "modules")]
pub fn sandbox_scratch_root(state_dir: &Path) -> PathBuf {
state_dir.join("artifacts").join("sandbox-scratch")
}
/// A fresh per-call scratch directory, removed after the module acknowledges execution cleanup.
+#[cfg(feature = "modules")]
pub(super) struct CallDir {
pub(super) path: PathBuf,
kind: &'static str,
}
+#[cfg(feature = "modules")]
impl CallDir {
pub(super) fn create(root: PathBuf, kind: &'static str) -> anyhow::Result<Self> {
let path = root.join(uuid::Uuid::new_v4().to_string());
@@ -494,6 +502,7 @@ impl CallDir {
}
}
+#[cfg(feature = "modules")]
impl Drop for CallDir {
fn drop(&mut self) {
match std::fs::remove_dir_all(&self.path) {