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 sandboxed shell execution
Steven Enamakel7b988c03cfa6
diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rsindex d23504aa3e..52247b4858 100644--- a/crates/openhuman-core/src/sandbox/ops.rs+++ b/crates/openhuman-core/src/sandbox/ops.rs@@ -291,6 +291,20 @@ pub async fn execute_in_sandbox(working_dir: &Path,extra_env: HashMap<OsString, OsString>,timeout: Duration,+) -> anyhow::Result<SandboxExecResult> {+ execute_in_sandbox_metered(policy, command, working_dir, extra_env, timeout, None).await+}++/// [`execute_in_sandbox`] that feeds `meter` with the command's output as it+/// streams (the native backends; Docker reports elapsed time only), for the+/// shell tool's progress line.+pub(crate) async fn execute_in_sandbox_metered(+ policy: &SandboxPolicy,+ command: &str,+ working_dir: &Path,+ extra_env: HashMap<OsString, OsString>,+ timeout: Duration,+ meter: Option<super::shell_progress::ShellOutputMeter>,) -> 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@@ -341,7 +355,16 @@ pub async fn execute_in_sandbox(anyhow::anyhow!("Cannot read module configuration: {error}")})?,};- execute_unsandboxed(&config, policy, command, working_dir, &extra_env, timeout).await+ execute_unsandboxed(+ &config,+ policy,+ command,+ working_dir,+ &extra_env,+ timeout,+ meter,+ )+ .await}SandboxBackendKind::Local => {crate::config::ensure_usable_cwd(working_dir)?;@@ -362,6 +385,7 @@ pub async fn execute_in_sandbox(&extra_env,timeout,explicitly_requested,+ meter,).await}@@ -446,6 +470,7 @@ async fn execute_unsandboxed(working_dir: &Path,extra_env: &HashMap<OsString, OsString>,timeout: Duration,+ meter: Option<super::shell_progress::ShellOutputMeter>,) -> anyhow::Result<SandboxExecResult> {let mut env = std::collections::BTreeMap::new();for (name, value) in extra_env {@@ -464,6 +489,7 @@ async fn execute_unsandboxed(env,timeout,false,+ meter,).await}diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rsindex 9ef0d06060..beb4c438a5 100644--- a/crates/openhuman-core/src/tools/impl/system/shell.rs+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs@@ -297,7 +297,7 @@ impl ShellTool {let (allowed, result) = crate::sandbox::shell_progress::with_shell_progress(context,crate::sandbox::shell_progress::HEARTBEAT_INTERVAL,- self.run_with_security_in_context(command, requested_timeout, context),+ |meter| self.run_with_security_in_context(command, requested_timeout, context, meter),).await;let duration_ms = u64::try_from(start.elapsed().as_millis()).unwrap_or(u64::MAX);@@ -329,7 +329,7 @@ impl ShellTool {command: &str,requested_timeout: Option<u64>,) -> (bool, ToolResult) {- self.run_with_security_in_context(command, requested_timeout, None)+ self.run_with_security_in_context(command, requested_timeout, None, None).await}@@ -338,6 +338,7 @@ impl ShellTool {command: &str,requested_timeout: Option<u64>,context: Option<&dyn ToolRunContext>,+ meter: Option<crate::sandbox::shell_progress::ShellOutputMeter>,) -> (bool, ToolResult) {// Revalidate facts immediately before execution. The authorization// hook supplies the same module-owned parser to the harness gate; this@@ -408,7 +409,7 @@ impl ShellTool {let action_dir = saas_action_dir;return match resolved {Ok(policy) => {- self.run_in_policy(policy, command, requested_timeout, &action_dir)+ self.run_in_policy(policy, command, requested_timeout, &action_dir, meter).await}Err(why) => {@@ -437,7 +438,7 @@ impl ShellTool {if sandbox_required {let action_dir = self.effective_action_dir_for_context(context);return self- .run_sandboxed(command, requested_timeout, &action_dir)+ .run_sandboxed(command, requested_timeout, &action_dir, meter).await;}@@ -614,6 +615,7 @@ impl ShellTool {run.env = env;run.python_utf8 = true;run.hide_window = self.runtime.hide_window();+ run.meter = meter;let result = crate::sandbox::shell_exec::run(&config, run).await;(true, exec_result(result, effective))}@@ -625,6 +627,7 @@ impl ShellTool {command: &str,requested_timeout: Option<u64>,action_dir: &Path,+ meter: Option<crate::sandbox::shell_progress::ShellOutputMeter>,) -> (bool, ToolResult) {let config = crate::config::RuntimeConfig::default();let policy = crate::sandbox::resolve_sandbox_policy(@@ -634,7 +637,7 @@ impl ShellTool {&config,false,);- self.run_in_policy(policy, command, requested_timeout, action_dir)+ self.run_in_policy(policy, command, requested_timeout, action_dir, meter).await}@@ -645,6 +648,7 @@ impl ShellTool {command: &str,requested_timeout: Option<u64>,action_dir: &Path,+ meter: Option<crate::sandbox::shell_progress::ShellOutputMeter>,) -> (bool, ToolResult) {use crate::sandbox;@@ -677,7 +681,10 @@ impl ShellTool {);let result =- sandbox::execute_in_sandbox(&policy, command, action_dir, extra_env, effective).await;+ sandbox::ops::execute_in_sandbox_metered(+ &policy, command, action_dir, extra_env, effective, meter,+ )+ .await;(true, exec_result(result, effective))}}