The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix: enforce explicitly selected sandbox backends
Steven Enamakel9502a6025792
diff --git a/crates/openhuman-core/src/sandbox/mod.rs b/crates/openhuman-core/src/sandbox/mod.rsindex 36dbd4be8f..efced610b8 100644--- a/crates/openhuman-core/src/sandbox/mod.rs+++ b/crates/openhuman-core/src/sandbox/mod.rs@@ -21,8 +21,8 @@ pub mod schemas;pub mod types;pub use ops::{- build_elevated_op, create_sandbox_backend, execute_in_sandbox, is_elevated_op,- resolve_sandbox_policy,+ build_elevated_op, command_requires_sandbox, create_sandbox_backend, execute_in_sandbox,+ is_elevated_op, resolve_sandbox_policy,};pub use schemas::{all_controller_schemas as all_sandbox_controller_schemas,diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rsindex 825fbd0d86..5143320bdb 100644--- a/crates/openhuman-core/src/sandbox/ops.rs+++ b/crates/openhuman-core/src/sandbox/ops.rs@@ -9,7 +9,7 @@ use super::types::{};use crate::agent::harness::definition::SandboxMode;use crate::agent::platform_shell;-use crate::config::RuntimeConfig;+use crate::config::{RuntimeConfig, SandboxBackend, SandboxConfig};use crate::sandbox::cwd_jail::{self, Jail, NoopBackend};use std::collections::HashMap;use std::ffi::OsString;@@ -52,6 +52,31 @@ pub fn sandbox_off_value(value: Option<&str>) -> bool {)}+/// Whether a command tool must use the sandbox execution path. An explicit+/// backend in the active config is an operator requirement even when the+/// agent definition uses the usual `SandboxMode::None` default.+pub async fn command_requires_sandbox() -> Result<bool, String> {+ if crate::core::runtime::is_saas() {+ // SaaS has its own container routing. This host config does not+ // select that tenant's execution backend.+ return Ok(false);+ }+ if matches!(+ crate::agent::harness::current_sandbox_mode(),+ Some(SandboxMode::Sandboxed)+ ) {+ return Ok(true);+ }+ let config = crate::config::ops::load_config_with_timeout().await?;+ Ok(matches!(+ config.sandbox.backend,+ SandboxBackend::Landlock+ | SandboxBackend::Firejail+ | SandboxBackend::Bubblewrap+ | SandboxBackend::Docker+ ))+}+fn sandbox_disabled_by_host() -> bool {sandbox_off_value(std::env::var(SANDBOX_OFF_ENV).ok().as_deref())}@@ -226,6 +251,19 @@ pub async fn execute_in_sandbox(extra_env: HashMap<OsString, OsString>,timeout: Duration,) -> anyhow::Result<SandboxExecResult> {+ // The saved backend is an operator's explicit isolation requirement. It+ // must be checked at the spawn boundary, including callers that resolved+ // their policy from an older or default RuntimeConfig.+ let mut effective_policy = policy.clone();+ let explicitly_requested = if crate::core::runtime::is_saas() {+ false+ } else {+ let config = crate::config::ops::load_config_with_timeout()+ .await+ .map_err(|e| anyhow::anyhow!("Cannot read sandbox configuration: {e}"))?;+ apply_requested_backend(&mut effective_policy, &config.sandbox, &config.runtime)?+ };+ let policy = &effective_policy;// Validate the working directory up front so a missing/bad action_dir// surfaces an actionable, path-naming error here rather than an opaque OS// error 267 (ERROR_DIRECTORY) at spawn time — parity with the unsandboxed@@ -243,7 +281,15 @@ pub async fn execute_in_sandbox(}SandboxBackendKind::Local => {crate::config::ensure_usable_cwd(working_dir)?;- execute_local_jail(policy, command, working_dir, &extra_env, timeout).await+ execute_local_jail(+ policy,+ command,+ working_dir,+ &extra_env,+ timeout,+ explicitly_requested,+ )+ .await}SandboxBackendKind::Docker => {crate::config::ensure_usable_cwd(&policy.workspace_root)?;@@ -258,6 +304,60 @@ pub async fn execute_in_sandbox(}}+/// Apply an operator-selected backend. Auto retains the caller's existing+/// policy, and None is the operator's deliberate opt-out.+pub(crate) fn apply_requested_backend(+ policy: &mut SandboxPolicy,+ sandbox: &SandboxConfig,+ runtime: &RuntimeConfig,+) -> anyhow::Result<bool> {+ match &sandbox.backend {+ SandboxBackend::Auto => Ok(false),+ SandboxBackend::None => {+ policy.backend = SandboxBackendKind::None;+ Ok(false)+ }+ SandboxBackend::Docker => {+ if policy.backend == SandboxBackendKind::Local {+ policy.read_only_mounts.clear();+ policy.read_write_mounts.clear();+ }+ policy.backend = SandboxBackendKind::Docker;+ let dc = &runtime.docker;+ policy.docker_overrides = Some(super::types::DockerOverrides {+ image: Some(dc.image.clone()),+ network: Some(dc.network.clone()),+ memory_limit_mb: dc.memory_limit_mb,+ cpu_limit: dc.cpu_limit,+ read_only_rootfs: Some(dc.read_only_rootfs),+ extra_caps_drop: vec![],+ });+ Ok(true)+ }+ SandboxBackend::Landlock => {+ let backend = cwd_jail::default_backend();+ if backend.name() != "landlock" || !backend.is_available() {+ anyhow::bail!("Landlock sandbox was explicitly requested but is unavailable");+ }+ if policy.backend != SandboxBackendKind::Local {+ let grants =+ resolve_local_jail_grants(dirs::home_dir().as_deref(), &runtime.local_jail);+ policy.read_only_mounts = grants.read_only;+ policy.read_write_mounts = grants.read_write;+ }+ policy.backend = SandboxBackendKind::Local;+ policy.docker_overrides = None;+ Ok(true)+ }+ SandboxBackend::Firejail => {+ anyhow::bail!("Firejail sandbox was explicitly requested but this build has no Firejail execution backend")+ }+ SandboxBackend::Bubblewrap => {+ anyhow::bail!("Bubblewrap sandbox was explicitly requested but this build has no Bubblewrap execution backend")+ }+ }+}+/// Passthrough execution with no sandbox (for `SandboxBackendKind::None`).async fn execute_unsandboxed(command: &str,@@ -376,6 +476,7 @@ async fn execute_local_jail(working_dir: &Path,extra_env: &HashMap<OsString, OsString>,timeout: Duration,+ explicitly_requested: bool,) -> anyhow::Result<SandboxExecResult> {let mut jail = Jail::new(&policy.workspace_root, "sandbox.agent");if !policy.allow_network {@@ -432,8 +533,11 @@ async fn execute_local_jail(}let os_backend = cwd_jail::default_backend();+ if explicitly_requested && (os_backend.name() != "landlock" || !os_backend.is_available()) {+ anyhow::bail!("Landlock sandbox was explicitly requested but is unavailable");+ }let spawn_result = if os_backend.is_available() {- cwd_jail::spawn(&jail, cmd)+ cwd_jail::spawn_with(os_backend.as_ref(), &jail, cmd)} else {tracing::debug!("[sandbox:local] OS backend unavailable, using noop");cwd_jail::spawn_with(&NoopBackend, &jail, cmd)diff --git a/crates/openhuman-core/src/sandbox/schemas.rs b/crates/openhuman-core/src/sandbox/schemas.rsindex e42ab709c4..5776fade41 100644--- a/crates/openhuman-core/src/sandbox/schemas.rs+++ b/crates/openhuman-core/src/sandbox/schemas.rs@@ -192,13 +192,17 @@ fn handle_status(params: Map<String, Value>) -> ControllerFuture {}};- let policy = super::ops::resolve_sandbox_policy(+ let mut policy = super::ops::resolve_sandbox_policy(mode,&config.workspace_dir,&config.workspace_dir,&config.runtime,is_remote,);+ if !crate::core::runtime::is_saas() {+ super::ops::apply_requested_backend(&mut policy, &config.sandbox, &config.runtime)+ .map_err(|e| e.to_string())?;+ }let handle = super::ops::create_sandbox_backend(&policy).await;to_json(Outcome::new(handle, vec![]))})@@ -241,13 +245,17 @@ fn handle_resolve_policy(params: Map<String, Value>) -> ControllerFuture {// embedder-supplied config carries whatever `CoreBuilder::action_dir(..)`// set directly. Re-deriving it here from `action_dir_override` alone// would silently ignore an embedder's programmatic `action_dir` (#6081).- let policy = super::ops::resolve_sandbox_policy(+ let mut policy = super::ops::resolve_sandbox_policy(mode,&config.action_dir,&config.workspace_dir,&config.runtime,is_remote,);+ if !crate::core::runtime::is_saas() {+ super::ops::apply_requested_backend(&mut policy, &config.sandbox, &config.runtime)+ .map_err(|e| e.to_string())?;+ }to_json(Outcome::new(policy, vec![]))})}diff --git a/crates/openhuman-core/src/tools/impl/system/node_exec.rs b/crates/openhuman-core/src/tools/impl/system/node_exec.rsindex 76b647388c..f7d82ba1b5 100644--- a/crates/openhuman-core/src/tools/impl/system/node_exec.rs+++ b/crates/openhuman-core/src/tools/impl/system/node_exec.rs@@ -249,16 +249,17 @@ impl NodeExecTool {unreachable!("guarded above")};- // When the agent's sandbox mode is `Sandboxed`, route execution- // through the sandbox backend (Docker / OS-level `cwd_jail` /- // documented noop) instead of the native runtime path. Mirrors- // the wiring in `ShellTool::run_with_security` (PR #3261) so- // node_exec gets the same isolation guarantees as shell. The- // security/rate-limit checks above still apply.- if matches!(- crate::agent::harness::current_sandbox_mode(),- Some(crate::agent::harness::definition::SandboxMode::Sandboxed)- ) {+ // Route sandboxed agents and explicit operator backend selections+ // through the shared sandbox path before considering the native pool.+ let sandbox_required = match sandbox::command_requires_sandbox().await {+ Ok(required) => required,+ Err(err) => {+ return Ok(ToolResult::error(format!(+ "Cannot read sandbox configuration: {err}"+ )))+ }+ };+ if sandbox_required {return Ok(self.run_sandboxed(&path_policy, &command, &resolved.bin_dir, explicit_timeout).await);diff --git a/crates/openhuman-core/src/tools/impl/system/npm_exec.rs b/crates/openhuman-core/src/tools/impl/system/npm_exec.rsindex f542aab6a5..11293c7b1e 100644--- a/crates/openhuman-core/src/tools/impl/system/npm_exec.rs+++ b/crates/openhuman-core/src/tools/impl/system/npm_exec.rs@@ -251,16 +251,17 @@ impl NpmExecTool {}let command = parts.join(" ");- // When the agent's sandbox mode is `Sandboxed`, route execution- // through the sandbox backend (Docker / OS-level `cwd_jail` /- // documented noop) instead of the native runtime path. Mirrors- // the wiring in `ShellTool::run_with_security` (PR #3261) so- // npm_exec gets the same isolation guarantees as shell. The- // security/rate-limit checks above still apply.- if matches!(- crate::agent::harness::current_sandbox_mode(),- Some(crate::agent::harness::definition::SandboxMode::Sandboxed)- ) {+ // Route sandboxed agents and explicit operator backend selections+ // through the shared sandbox path before native execution.+ let sandbox_required = match sandbox::command_requires_sandbox().await {+ Ok(required) => required,+ Err(err) => {+ return Ok(ToolResult::error(format!(+ "Cannot read sandbox configuration: {err}"+ )))+ }+ };+ if sandbox_required {return Ok(self.run_sandboxed(&path_policy,diff --git a/crates/openhuman-core/src/tools/impl/system/python_exec.rs b/crates/openhuman-core/src/tools/impl/system/python_exec.rsindex d78261a606..9410dc7e59 100644--- a/crates/openhuman-core/src/tools/impl/system/python_exec.rs+++ b/crates/openhuman-core/src/tools/impl/system/python_exec.rs@@ -247,11 +247,17 @@ impl PythonExecTool {unreachable!("guarded above")};- // Sandboxed agents route through the sandbox backend, mirroring node_exec.- if matches!(- crate::agent::harness::current_sandbox_mode(),- Some(crate::agent::harness::definition::SandboxMode::Sandboxed)- ) {+ // Sandboxed agents and explicit operator backend selections use the+ // sandbox path, mirroring node_exec.+ let sandbox_required = match sandbox::command_requires_sandbox().await {+ Ok(required) => required,+ Err(err) => {+ return Ok(ToolResult::error(format!(+ "Cannot read sandbox configuration: {err}"+ )))+ }+ };+ if sandbox_required {let bin_dir = resolved.python_bin.parent()diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rsindex 4fc56f5c4f..b6170d6636 100644--- a/crates/openhuman-core/src/tools/impl/system/shell.rs+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs@@ -387,13 +387,18 @@ impl ShellTool {};}- // When the agent's sandbox mode is `Sandboxed`, route execution- // through the sandbox backend (Docker or OS-level jail) instead- // of the normal runtime. Security checks above still apply.- if matches!(- crate::agent::harness::current_sandbox_mode(),- Some(crate::agent::harness::definition::SandboxMode::Sandboxed)- ) {+ // A sandboxed agent or an explicit operator backend uses the sandbox+ // execution path. Security checks above still apply.+ let sandbox_required = match crate::sandbox::command_requires_sandbox().await {+ Ok(required) => required,+ Err(err) => {+ return (+ false,+ ToolResult::error(format!("Cannot read sandbox configuration: {err}")),+ )+ }+ };+ if sandbox_required {let action_dir = self.effective_action_dir_for_context(context);return self.run_sandboxed(command, requested_timeout, &action_dir)