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(sandbox): preserve mandatory routing and refuse unmapped language tools
Steven Enamakel5731b131d768
diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rsindex 5143320bdb..8f65dfa4cc 100644--- a/crates/openhuman-core/src/sandbox/ops.rs+++ b/crates/openhuman-core/src/sandbox/ops.rs@@ -57,8 +57,11 @@ pub fn sandbox_off_value(value: Option<&str>) -> bool {/// 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.+ // Every SaaS command must enter the per-user container path, including+ // language tools whose agent definition does not request a sandbox.+ return Ok(true);+ }+ if sandbox_disabled_by_host() {return Ok(false);}if matches!(@@ -68,6 +71,9 @@ pub async fn command_requires_sandbox() -> Result<bool, String> {return Ok(true);}let config = crate::config::ops::load_config_with_timeout().await?;+ if config.sandbox.enabled == Some(false) {+ return Ok(false);+ }Ok(matches!(config.sandbox.backend,SandboxBackend::Landlock@@ -77,6 +83,37 @@ pub async fn command_requires_sandbox() -> Result<bool, String> {))}+/// Resolve the policy for a command tool before building its command line.+/// SaaS always uses the user's container; other hosts apply the operator's+/// backend selection while retaining an agent-level sandbox requirement.+pub(crate) async fn resolve_command_policy(+ action_dir: &Path,+ state_dir: &Path,+) -> Result<SandboxPolicy, String> {+ if crate::core::runtime::is_saas() {+ return crate::profiles::tools::sandbox_policy(action_dir, state_dir);+ }+ let config = match crate::config::ops::load_config_with_timeout().await {+ Ok(config) => config,+ Err(error) => {+ tracing::warn!(%error, "[sandbox] using default configuration for command policy");+ crate::config::Config::default()+ }+ };+ let mut policy = resolve_sandbox_policy(+ SandboxMode::Sandboxed,+ action_dir,+ state_dir,+ &config.runtime,+ false,+ );+ if config.sandbox.enabled != Some(false) && !sandbox_disabled_by_host() {+ apply_requested_backend(&mut policy, &config.sandbox, &config.runtime)+ .map_err(|error| error.to_string())?;+ }+ Ok(policy)+}+fn sandbox_disabled_by_host() -> bool {sandbox_off_value(std::env::var(SANDBOX_OFF_ENV).ok().as_deref())}@@ -255,13 +292,20 @@ pub async fn execute_in_sandbox(// 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() {+ if !crate::core::runtime::is_saas() && sandbox_disabled_by_host() {+ effective_policy.backend = SandboxBackendKind::None;+ }+ let explicitly_requested = if crate::core::runtime::is_saas() || sandbox_disabled_by_host() {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)?+ if config.sandbox.enabled == Some(false) {+ false+ } else {+ 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@@ -305,7 +349,7 @@ 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.+/// policy. None opts out only when no agent-level sandbox is required.pub(crate) fn apply_requested_backend(policy: &mut SandboxPolicy,sandbox: &SandboxConfig,@@ -313,10 +357,7 @@ pub(crate) fn apply_requested_backend() -> anyhow::Result<bool> {match &sandbox.backend {SandboxBackend::Auto => Ok(false),- SandboxBackend::None => {- policy.backend = SandboxBackendKind::None;- Ok(false)- }+ SandboxBackend::None => Ok(false),SandboxBackend::Docker => {if policy.backend == SandboxBackendKind::Local {policy.read_only_mounts.clear();diff --git a/crates/openhuman-core/src/tools/impl/system/node_exec.rs b/crates/openhuman-core/src/tools/impl/system/node_exec.rsindex f7d82ba1b5..eaef0c2e54 100644--- a/crates/openhuman-core/src/tools/impl/system/node_exec.rs+++ b/crates/openhuman-core/src/tools/impl/system/node_exec.rs@@ -23,6 +23,7 @@use crate::agent::host_runtime::RuntimeAdapter;use crate::runtime::javascript::NodeBootstrap;+use crate::sandbox;use crate::security::{CommandClass, GateDecision, SecurityPolicy};use crate::tools::schema_cache::static_schema;use async_trait::async_trait;@@ -452,40 +453,22 @@ impl NodeExecTool {Duration::from_secs(crate::tools::timeout::SANDBOX_UNBOUNDED_CAP_SECS)});- // Load the live `RuntimeConfig` so `resolve_sandbox_policy` derives- // the right backend (Docker / local / noop) from the operator's- // configuration instead of the unconfigured `RuntimeConfig::default()`.- // Falls back to defaults with a warning if the config load fails —- // a failed config read shouldn't block tool execution. (CodeRabbit- // finding on PR #3309.)- let runtime_cfg = match crate::config::ops::load_config_with_timeout().await {- Ok(cfg) => cfg.runtime,- Err(err) => {- tracing::warn!(- error = %err,- "[node_exec] failed to load live RuntimeConfig — falling back to defaults"- );- crate::config::RuntimeConfig::default()- }- };- // `is_remote_session = false` matches `ShellTool::run_sandboxed`'s- // current behavior (PR #3261). Threading the real session origin- // through requires a new `tokio::task_local!` next to- // `CURRENT_AGENT_SANDBOX_MODE` and is the same gap across all three- // shell-family tools; tracked separately so it can be fixed uniformly.- let policy = sandbox::resolve_sandbox_policy(- crate::agent::harness::definition::SandboxMode::Sandboxed,+ let policy = match sandbox::ops::resolve_command_policy(&security.action_dir,&security.workspace_dir,- &runtime_cfg,- false,- );+ )+ .await+ {+ Ok(policy) => policy,+ Err(why) => return ToolResult::error(format!("Sandbox unavailable: {why}")),+ };- tracing::debug!(- backend = ?policy.backend,- runtime_kind = ?runtime_cfg.kind,- "[node_exec] routing to sandbox backend"- );+ tracing::debug!(backend = ?policy.backend, "[node_exec] routing to sandbox backend");+ if policy.backend == sandbox::SandboxBackendKind::Docker {+ return ToolResult::error(+ "node_exec cannot use the Docker sandbox: its host Node.js binary and script paths are not mounted in the container",+ );+ }// Forward the managed Node.js bin dir on PATH so the child node// process can resolve `node`, `npm`, `npx`, `corepack` consistentlydiff --git a/crates/openhuman-core/src/tools/impl/system/npm_exec.rs b/crates/openhuman-core/src/tools/impl/system/npm_exec.rsindex 11293c7b1e..4b415b1942 100644--- a/crates/openhuman-core/src/tools/impl/system/npm_exec.rs+++ b/crates/openhuman-core/src/tools/impl/system/npm_exec.rs@@ -19,6 +19,7 @@use crate::agent::host_runtime::RuntimeAdapter;use crate::runtime::javascript::NodeBootstrap;+use crate::sandbox;use crate::security::{CommandClass, GateDecision, SecurityPolicy};use crate::tools::schema_cache::static_schema;use async_trait::async_trait;@@ -374,40 +375,23 @@ impl NpmExecTool {Duration::from_secs(crate::tools::timeout::SANDBOX_UNBOUNDED_CAP_SECS)});- // Load the live `RuntimeConfig` so `resolve_sandbox_policy` derives- // the right backend (Docker / local / noop) from the operator's- // configuration instead of the unconfigured `RuntimeConfig::default()`.- // Falls back to defaults with a warning if the config load fails —- // a failed config read shouldn't block tool execution. (CodeRabbit- // finding on PR #3309.)- let runtime_cfg = match crate::config::ops::load_config_with_timeout().await {- Ok(cfg) => cfg.runtime,- Err(err) => {- tracing::warn!(- error = %err,- "[npm_exec] failed to load live RuntimeConfig — falling back to defaults"- );- crate::config::RuntimeConfig::default()- }- };- // `is_remote_session = false` matches `ShellTool::run_sandboxed`'s- // current behavior (PR #3261). Threading the real session origin- // through requires a new `tokio::task_local!` next to- // `CURRENT_AGENT_SANDBOX_MODE` and is the same gap across all three- // shell-family tools; tracked separately so it can be fixed uniformly.- let policy = sandbox::resolve_sandbox_policy(- crate::agent::harness::definition::SandboxMode::Sandboxed,+ let policy = match sandbox::ops::resolve_command_policy(&security.action_dir,&security.workspace_dir,- &runtime_cfg,- false,- );+ )+ .await+ {+ Ok(policy) => policy,+ Err(why) => return ToolResult::error(format!("Sandbox unavailable: {why}")),+ };- tracing::debug!(- backend = ?policy.backend,- runtime_kind = ?runtime_cfg.kind,- "[npm_exec] routing to sandbox backend"- );+ if policy.backend == sandbox::SandboxBackendKind::Docker {+ return ToolResult::error(+ "npm_exec cannot use the Docker sandbox: its host npm and Node.js binaries are not mounted in the container",+ );+ }++ tracing::debug!(backend = ?policy.backend, "[npm_exec] routing to sandbox backend");// Forward the managed Node.js bin dir on PATH so npm child invocations// (e.g. `npm run` spawning user scripts) resolve `node`/`npx`diff --git a/crates/openhuman-core/src/tools/impl/system/python_exec.rs b/crates/openhuman-core/src/tools/impl/system/python_exec.rsindex 9410dc7e59..5ec0d45af7 100644--- a/crates/openhuman-core/src/tools/impl/system/python_exec.rs+++ b/crates/openhuman-core/src/tools/impl/system/python_exec.rs@@ -18,6 +18,7 @@use crate::agent::host_runtime::RuntimeAdapter;use crate::runtime::python::PythonBootstrap;+use crate::sandbox;use crate::security::{CommandClass, GateDecision, SecurityPolicy};use async_trait::async_trait;use serde_json::json;@@ -424,23 +425,21 @@ impl PythonExecTool {Duration::from_secs(crate::tools::timeout::SANDBOX_UNBOUNDED_CAP_SECS)});- let runtime_cfg = match crate::config::ops::load_config_with_timeout().await {- Ok(cfg) => cfg.runtime,- Err(err) => {- tracing::warn!(- error = %err,- "[python_exec] failed to load live RuntimeConfig — falling back to defaults"- );- crate::config::RuntimeConfig::default()- }- };- let policy = sandbox::resolve_sandbox_policy(- crate::agent::harness::definition::SandboxMode::Sandboxed,+ let policy = match sandbox::ops::resolve_command_policy(&security.action_dir,&security.workspace_dir,- &runtime_cfg,- false,- );+ )+ .await+ {+ Ok(policy) => policy,+ Err(why) => return ToolResult::error(format!("Sandbox unavailable: {why}")),+ };++ if policy.backend == sandbox::SandboxBackendKind::Docker {+ return ToolResult::error(+ "python_exec cannot use the Docker sandbox: its host Python binary and script paths are not mounted in the container",+ );+ }let mut extra_env = std::collections::HashMap::new();let host_path = std::env::var("PATH").unwrap_or_default();