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
refactor(agent): read sandbox mode from tool context instead of task-local
Steven Enamakelca7f6d6c6d9a
diff --git a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rsindex b35e8db205..6dcba7b193 100644--- a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs+++ b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs@@ -42,23 +42,6 @@ pub(crate) fn new_tool_result_store()}-/// A store over the layout releases before the detached store used,-/// `<action_dir>/artifacts/tool-results/`. Never written to: it exists so the-/// session host can keep sweeping stale sessions that older builds left in the-/// user's project.-pub(crate) fn legacy_action_dir_store(- action_dir: std::path::PathBuf,- session_key: impl Into<String>,-) -> ToolResultArtifactStore {- ToolResultArtifactStore::new(- action_dir,- session_key,- std::sync::Arc::new(SanitizingRedactor),- READ_TOOL,- FileReadTool::MAX_FILE_SIZE_BYTES,- )-}-/// The artifact a tool call reads, if any — `file_read`, possibly wrapped in/// `use_skill` (#6284).///diff --git a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rsindex 21d08cc1a1..f3a7ad058e 100644--- a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs+++ b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs@@ -68,19 +68,6 @@ async fn threshold_persists_outside_the_project_and_reads_back() {.contains("Bearer credential-marker-redact-me-123456"));}-/// The legacy store still reads the layout older builds wrote, so its sweep-/// finds what they left in a project.-#[test]-fn legacy_store_is_rooted_in_the_action_dir() {- let tmp = tempfile::tempdir().unwrap();- let legacy = legacy_action_dir_store(tmp.path().to_path_buf(), "s");- assert!(!legacy.is_detached());- assert_eq!(- legacy.path_for_read_tool("shell", Some("c")),- "artifacts/tool-results/s/shell/c.txt"- );-}-/// The vocabulary passed to the crate is OpenHuman's: `file_read` reads,/// `use_skill` is the only wrapper followed.#[test]diff --git a/crates/openhuman-core/src/agent/session_host/artifact_wiring.rs b/crates/openhuman-core/src/agent/session_host/artifact_wiring.rsindex 67a98a6a78..ebb6142dd4 100644--- a/crates/openhuman-core/src/agent/session_host/artifact_wiring.rs+++ b/crates/openhuman-core/src/agent/session_host/artifact_wiring.rs@@ -6,9 +6,7 @@use std::path::{Path, PathBuf};-use crate::agent::harness::tool_result_artifacts::{- legacy_action_dir_store, new_tool_result_store,-};+use crate::agent::harness::tool_result_artifacts::new_tool_result_store;use tinyagents_harness::artifacts::tool_results::ToolResultArtifactStore;/// How long another session's tool-result artifacts survive before a later@@ -67,39 +65,13 @@ fn artifact_root(workspace_dir: &Path) -> PathBuf {/// their message.pub(super) fn build_artifact_store(workspace_dir: &Path,- workspace_descriptor: Option<&tinytools::WorkspaceDescriptor>,- action_dir: &Path,session_key: &str,) -> ToolResultArtifactStore {let store = new_tool_result_store(artifact_root(workspace_dir), session_key);prune(&store, "workspace");- // Older builds wrote into the project itself. Keep sweeping those- // directories with the same age rule they always had, so the files they- // left behind still go away; nothing is written there any more.- for legacy_root in legacy_roots(workspace_descriptor, action_dir) {- prune(- &legacy_action_dir_store(legacy_root, session_key),- "legacy action-dir",- );- }store}-/// Every root a pre-detached build could have written artifacts under: the-/// descriptor's root when a turn carried one, and the action directory.-fn legacy_roots(- workspace_descriptor: Option<&tinytools::WorkspaceDescriptor>,- action_dir: &Path,-) -> Vec<PathBuf> {- let mut roots = vec![action_dir.to_path_buf()];- if let Some(descriptor) = workspace_descriptor {- if descriptor.root != action_dir {- roots.push(descriptor.root.clone());- }- }- roots-}-fn prune(store: &ToolResultArtifactStore, which: &str) {match store.prune_stale_sessions(ARTIFACT_RETENTION) {Ok(0) => {}diff --git a/crates/openhuman-core/src/agent/session_host/artifact_wiring_tests.rs b/crates/openhuman-core/src/agent/session_host/artifact_wiring_tests.rsindex 468b87d698..95a33d95e2 100644--- a/crates/openhuman-core/src/agent/session_host/artifact_wiring_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/artifact_wiring_tests.rs@@ -41,26 +41,16 @@ fn stale_session(root: &Path, session: &str) -> PathBuf {}/// The store writes under the workspace, never the action directory, whether-/// or not the turn carries a workspace descriptor.+/// with absolute pointers independent of the turn's working directory.#[test]fn the_store_is_rooted_in_the_workspace_not_the_action_dir() {let tmp = tempfile::tempdir().unwrap();let workspace = tmp.path().join("workspace");- let action = tmp.path().join("project");- let descriptor = tinytools::WorkspaceDescriptor {- root: tmp.path().join("checkout"),- trusted_roots: Vec::new(),- policy_id: String::new(),- sandbox: Default::default(),- };-- for descriptor in [None, Some(&descriptor)] {- let store = build_artifact_store(&workspace, descriptor, &action, "s");- assert!(store.is_detached());- assert_eq!(store.root(), tool_result_artifacts_dir(&workspace));- let pointer = store.path_for_read_tool("shell", Some("c"));- assert!(Path::new(&pointer).starts_with(workspace.join("artifacts/tool-results")));- }+ let store = build_artifact_store(&workspace, "s");+ assert!(store.is_detached());+ assert_eq!(store.root(), tool_result_artifacts_dir(&workspace));+ let pointer = store.path_for_read_tool("shell", Some("c"));+ assert!(Path::new(&pointer).starts_with(workspace.join("artifacts/tool-results")));}/// Workspace retention never deletes files from the agent's project after@@ -77,29 +67,10 @@ fn workspace_retention_leaves_legacy_project_artifacts_alone() {std::fs::write(fresh.join("call.txt"), "recent").unwrap();let detached_stale = stale_session(&tool_result_artifacts_dir(&workspace), "older");- build_artifact_store(&workspace, None, &action, "current");+ build_artifact_store(&workspace, "current");assert!(stale.exists(), "project files are outside workspace retention");assert!(fresh.join("call.txt").exists(), "a fresh one is kept");assert!(!detached_stale.exists(), "the workspace store is swept too");}-#[test]-fn legacy_roots_include_a_distinct_descriptor_root_once() {- let action = PathBuf::from("/p/action");- let descriptor = |root: &str| tinytools::WorkspaceDescriptor {- root: PathBuf::from(root),- trusted_roots: Vec::new(),- policy_id: String::new(),- sandbox: Default::default(),- };- assert_eq!(legacy_roots(None, &action), vec![action.clone()]);- assert_eq!(- legacy_roots(Some(&descriptor("/p/action")), &action),- vec![action.clone()]- );- assert_eq!(- legacy_roots(Some(&descriptor("/p/checkout")), &action),- vec![action.clone(), PathBuf::from("/p/checkout")]- );-}diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rsindex 5f3e73bc4d..5c51549b72 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs@@ -739,8 +739,6 @@ impl OpenHumanSessionHost {};let artifact_store = super::artifact_wiring::build_artifact_store(&self.workspace_dir,- self.workspace_descriptor.as_ref(),- &self.action_dir,&self.event_session_id,);diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rsindex 1557889d0f..b862bb3a0c 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs@@ -375,6 +375,17 @@ pub struct OpenHumanRunContext {#[derive(Clone, Debug, Default)]pub(crate) struct HostOperationContext {pub(crate) origin: Option<AgentTurnOrigin>,+ pub(crate) sandbox_mode: Option<SandboxMode>,+}++/// Reads the calling agent's sandbox policy from the explicit tool carrier.+/// Direct tool dispatch has no agent-specific mode.+pub(crate) fn sandbox_mode_for_tool(context: Option<&dyn tinytools::ToolRunContext>) -> Option<SandboxMode> {+ context+ .and_then(tinytools::ToolRunContext::host_extension)+ .and_then(|extension| extension.downcast_ref::<tinyagents_harness::tool::ToolExecutionContext>())+ .and_then(|context| context.state::<HostOperationContext>())+ .and_then(|host| host.sandbox_mode)}impl Default for OpenHumanRunContext {@@ -549,6 +560,7 @@ impl OpenHumanRunContext {let workspace = self.workspace.clone();let host_operations = Arc::new(HostOperationContext {origin: self.origin.clone(),+ sandbox_mode: self.sandbox_mode,});let context = tinyagents_harness::context::RunContext::new(config, self).with_cancellation(cancellation)diff --git a/crates/openhuman-core/src/integrations/composio/action_tool.rs b/crates/openhuman-core/src/integrations/composio/action_tool.rsindex 1c4a9ead13..c9f279603d 100644--- a/crates/openhuman-core/src/integrations/composio/action_tool.rs+++ b/crates/openhuman-core/src/integrations/composio/action_tool.rs@@ -35,11 +35,11 @@ use serde_json::Value;use super::providers::ToolScope;use super::tools::resolve_action_scope;-use crate::agent::harness::current_sandbox_mode;+use crate::agent::tinyagents::host::run_context::sandbox_mode_for_tool;use crate::agent::harness::definition::SandboxMode;use crate::config::rpc as config_rpc;use crate::config::Config;-use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};+use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult, ToolCallOptions, ToolRunContext};/// A single Composio action exposed as a first-class tool.pub struct ComposioActionTool {@@ -239,9 +239,16 @@ impl Tool for ComposioActionTool {}async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {- let (config, outcome) = Box::pin(self.execute_unredacted(args)).await;+ let (config, outcome) = Box::pin(self.execute_unredacted(args, None)).await;super::tools::redact_composio_outcome(&config, outcome)}+ async fn execute_with_context(+ &self, args: Value, _options: ToolCallOptions, context: Option<&dyn ToolRunContext>,+ ) -> anyhow::Result<ToolResult> {+ let (config, outcome) = Box::pin(self.execute_unredacted(args, sandbox_mode_for_tool(context))).await;+ super::tools::redact_composio_outcome(&config, outcome)+ }+}impl ComposioActionTool {@@ -249,7 +256,7 @@ impl ComposioActionTool {/// outcome, so [`Tool::execute`] always redacts against the same/// credential that dispatched — for both a spawn-time config and a/// deferred instance with none.- async fn execute_unredacted(&self, args: Value) -> (Box<Config>, anyhow::Result<ToolResult>) {+ async fn execute_unredacted(&self, args: Value, sandbox_mode: Option<SandboxMode>) -> (Box<Config>, anyhow::Result<ToolResult>) {// Boxed from the moment it exists, not just at the return: this// local is held across every await point below, and `Config` is a// large top-level struct — inlining it by value in the generated@@ -263,7 +270,7 @@ impl ComposioActionTool {// surface. The dispatcher path (`composio_execute`) and this// per-action path are the only two routes to the Composio// backend; both must honour the same invariant.- if matches!(current_sandbox_mode(), Some(SandboxMode::ReadOnly)) {+ if matches!(sandbox_mode, Some(SandboxMode::ReadOnly)) {let scope = resolve_action_scope(&self.action_name).await;if matches!(scope, ToolScope::Write | ToolScope::Admin) {tracing::info!(diff --git a/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs b/crates/openhuman-core/src/integrations/composio/action_tool_tests.rsindex 4c401e0b93..23aacb247a 100644--- a/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs@@ -487,7 +487,7 @@ fn deferred_instance_returns_live_config_for_redaction() {);// Boxed exactly like `Tool::execute` does.- let (live_config, outcome) = Box::pin(t.execute_unredacted(serde_json::json!({}))).await;+ let (live_config, outcome) = Box::pin(t.execute_unredacted(serde_json::json!({}), None)).await;let first = outcome.expect("contract-gate surface is Ok(error result)");assert!(first.is_error && error_text(&first).contains("Input JSON schema"),diff --git a/crates/openhuman-core/src/integrations/composio/tools/execute.rs b/crates/openhuman-core/src/integrations/composio/tools/execute.rsindex 01a4584b35..f9db002725 100644--- a/crates/openhuman-core/src/integrations/composio/tools/execute.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/execute.rs@@ -9,11 +9,11 @@ use serde_json::{json, Value};use super::live_config::live_composio_config;use super::redact::redact_composio_outcome;-use crate::agent::harness::current_sandbox_mode;+use crate::agent::tinyagents::host::run_context::sandbox_mode_for_tool;use crate::agent::harness::definition::SandboxMode;use crate::config::Config;use crate::integrations::composio::task_recency_context::current_task_recency_window;-use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};+use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult, ToolCallOptions, ToolRunContext};use super::super::ops::load_user_scope_pref;use super::super::providers::{toolkit_from_slug, ToolScope};@@ -100,9 +100,16 @@ impl Tool for ComposioExecuteTool {ToolCategory::Workflow}async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {- let (config, outcome) = Box::pin(self.execute_unredacted(args)).await;+ let (config, outcome) = Box::pin(self.execute_unredacted(args, None)).await;redact_composio_outcome(&config, outcome)}+ async fn execute_with_context(+ &self, args: Value, _options: ToolCallOptions, context: Option<&dyn ToolRunContext>,+ ) -> anyhow::Result<ToolResult> {+ let (config, outcome) = Box::pin(self.execute_unredacted(args, sandbox_mode_for_tool(context))).await;+ redact_composio_outcome(&config, outcome)+ }+}impl ComposioExecuteTool {@@ -110,7 +117,7 @@ impl ComposioExecuteTool {/// so [`Tool::execute`] redacts against the same credential that ran —/// not the possibly-stale snapshot captured when this tool was/// registered.- async fn execute_unredacted(&self, args: Value) -> (Box<Config>, anyhow::Result<ToolResult>) {+ async fn execute_unredacted(&self, args: Value, sandbox_mode: Option<SandboxMode>) -> (Box<Config>, anyhow::Result<ToolResult>) {let tool = args.get("tool").and_then(|v| v.as_str())@@ -164,7 +171,7 @@ impl ComposioExecuteTool {// composio surface. `SandboxMode::None` / `Sandboxed` (and the// `None` task-local value used by direct CLI / JSON-RPC / unit// tests) pass through unchanged.- if matches!(current_sandbox_mode(), Some(SandboxMode::ReadOnly)) {+ if matches!(sandbox_mode, Some(SandboxMode::ReadOnly)) {let scope = resolve_action_scope(&tool).await;if matches!(scope, ToolScope::Write | ToolScope::Admin) {tracing::info!(diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rsindex 28e486924b..38c3a1deca 100644--- a/crates/openhuman-core/src/sandbox/ops.rs+++ b/crates/openhuman-core/src/sandbox/ops.rs@@ -55,7 +55,7 @@ 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> {+pub async fn command_requires_sandbox(sandbox_mode: Option<SandboxMode>) -> Result<bool, String> {if crate::core::runtime::is_saas() {// Every SaaS command must enter the per-user container path, including// language tools whose agent definition does not request a sandbox.@@ -65,7 +65,7 @@ pub async fn command_requires_sandbox() -> Result<bool, String> {return Ok(false);}if matches!(- crate::agent::harness::current_sandbox_mode(),+ sandbox_mode,Some(SandboxMode::Sandboxed)) {return Ok(true);diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rsindex 60577a8fe8..4b2f3141d8 100644--- a/crates/openhuman-core/src/tools/impl/system/shell.rs+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs@@ -328,7 +328,7 @@ impl ShellTool {// 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 {+ let sandbox_required = match crate::sandbox::command_requires_sandbox(crate::agent::tinyagents::host::run_context::sandbox_mode_for_tool(context)).await {Ok(required) => required,Err(err) => {return (