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
feat(sandbox): add sandbox configuration and operations
Steven Enamakel30175bad4546
diff --git a/crates/openhuman-core/src/config/ops/sandbox.rs b/crates/openhuman-core/src/config/ops/sandbox.rsindex 234f39e3cb..e5e7e4f845 100644--- a/crates/openhuman-core/src/config/ops/sandbox.rs+++ b/crates/openhuman-core/src/config/ops/sandbox.rs@@ -42,7 +42,8 @@ pub async fn get_sandbox_settings() -> Result<Outcome<serde_json::Value>, Stringlet detected_backend = detect_os_sandbox_backend();let value = serde_json::json!({- "enabled": sandbox.enabled.unwrap_or(true),+ "enabled": sandbox.enabled.unwrap_or(true)+ && crate::core::runtime::ComponentSet::from_config(&config.components).sandbox,"backend": backend_str,"docker_image": docker.image,"docker_memory_limit_mb": docker.memory_limit_mb,diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rsindex 261f3a4ebe..bdaac78d0c 100644--- a/crates/openhuman-core/src/sandbox/ops.rs+++ b/crates/openhuman-core/src/sandbox/ops.rs@@ -66,7 +66,7 @@ pub async fn command_requires_sandbox(sandbox_mode: Option<SandboxMode>) -> Resureturn Ok(true);}let config = crate::config::ops::load_config_with_timeout().await?;- if config.sandbox.enabled == Some(false) {+ if config_disables_sandbox(&config) {return Ok(false);}Ok(matches!(@@ -98,7 +98,7 @@ pub(crate) async fn resolve_command_policy(&config.runtime,false,);- if config.sandbox.enabled != Some(false) && !sandbox_disabled_by_host() {+ if !config_disables_sandbox(&config) && !sandbox_disabled_by_host() {apply_requested_backend(&mut policy, &config.sandbox, &config.runtime, &config).await.map_err(|error| error.to_string())?;@@ -107,7 +107,25 @@ pub(crate) async fn resolve_command_policy(}fn sandbox_disabled_by_host() -> bool {- sandbox_off_value(std::env::var(SANDBOX_OFF_ENV).ok().as_deref())+ sandbox_off_value(std::env::var(SANDBOX_OFF_ENV).ok().as_deref()) || sandbox_component_off()+}++/// `[components] sandbox = false` in the ambient core context. With no context+/// the component is on, since the set only narrows.+pub(crate) fn sandbox_component_off() -> bool {+ let off = crate::core::runtime::context::CoreContext::current()+ .is_some_and(|ctx| !ctx.components().sandbox);+ if off {+ tracing::debug!("[sandbox] component 'sandbox' disabled, using the unsandboxed fallback");+ }+ off+}++/// The saved config says no isolation: the legacy `enabled = false` flag or+/// `[components] sandbox = false`.+fn config_disables_sandbox(config: &crate::config::Config) -> bool {+ config.sandbox.enabled == Some(false)+ || !crate::core::runtime::ComponentSet::from_config(&config.components).sandbox}/// Resolve a `SandboxPolicy` from the agent's `SandboxMode`, the@@ -297,7 +315,7 @@ pub async fn execute_in_sandbox(.await.map_err(|e| anyhow::anyhow!("Cannot read sandbox configuration: {e}"))?;module_config = Some(config.clone());- if config.sandbox.enabled == Some(false) {+ if config_disables_sandbox(&config) {false} else {apply_requested_backend(diff --git a/crates/openhuman-core/src/sandbox/schemas.rs b/crates/openhuman-core/src/sandbox/schemas.rsindex 0c5f85e2f6..d51f699873 100644--- a/crates/openhuman-core/src/sandbox/schemas.rs+++ b/crates/openhuman-core/src/sandbox/schemas.rs@@ -7,6 +7,15 @@ use crate::core::all::{ControllerFuture, RegisteredController};use crate::core::Outcome;use crate::core::{ControllerSchema, FieldSchema, TypeSchema};+/// Refuse with the typed `COMPONENT_DISABLED:sandbox` error while `[components]+/// sandbox` is off. Read from the ambient core context; with none, it is on.+fn gate() -> Result<(), String> {+ if super::ops::sandbox_component_off() {+ return Err(crate::core::runtime::components::component_disabled("sandbox").encode());+ }+ Ok(())+}+pub fn all_controller_schemas() -> Vec<ControllerSchema> {vec![schemas("status"),@@ -160,6 +169,7 @@ pub fn schemas(function: &str) -> ControllerSchema {/// backend instead was the conflation fixed in #6081.fn handle_status(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;let backend_str = params.get("backend").and_then(|v| v.as_str())@@ -216,6 +226,7 @@ fn handle_status(params: Map<String, Value>) -> ControllerFuture {fn handle_resolve_policy(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;let mode_str = params.get("sandbox_mode").and_then(|v| v.as_str())@@ -274,6 +285,7 @@ fn handle_resolve_policy(params: Map<String, Value>) -> ControllerFuture {fn handle_cleanup_orphans(_params: Map<String, Value>) -> ControllerFuture {Box::pin(async {+ gate()?;let config = match crate::config::ops::load_config_with_timeout().await {Ok(config) => config,Err(error) => return Err(error),@@ -290,6 +302,7 @@ fn handle_cleanup_orphans(_params: Map<String, Value>) -> ControllerFuture {fn handle_validate_policy(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {+ gate()?;let policy_val = params.get("policy").cloned().unwrap_or(Value::Null);let policy: super::types::SandboxPolicy = match serde_json::from_value(policy_val) {Ok(p) => p,