Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(agent): carry sandbox mode on the run context

Steven Enamakeld937f7764412
diff --git a/crates/openhuman-core/src/agent/bus.rs b/crates/openhuman-core/src/agent/bus.rs
index c18f3842ab..e98fff7b2d 100644
--- a/crates/openhuman-core/src/agent/bus.rs
+++ b/crates/openhuman-core/src/agent/bus.rs
@@ -31,7 +31,7 @@ use tinyagents_session::transcript::TranscriptMessage;
use tinytools::Tool;
use super::harness::definition::{AgentDefinitionRegistry, SandboxMode};
-use super::harness::{run_channel_turn_via_graph, with_current_sandbox_mode};
+use super::harness::run_channel_turn_via_graph;
use tinytools_std::file_state::with_file_state_agent_id;
/// Method name used to dispatch an agentic turn through the native bus.
@@ -264,8 +264,8 @@ async fn handle_agent_run_turn(req: AgentTurnRequest) -> Result<AgentTurnRespons
}
// Resolve the target agent's declared sandbox mode so any
- // tool executed inside the loop can read it via the
- // `CURRENT_AGENT_SANDBOX_MODE` task-local. Falls back to
+ // tool executed inside the loop receives it through the explicit
+ // host operation context. Falls back to
// `SandboxMode::None` when the request doesn't pin an agent
// id (legacy "generic unfiltered turn" path) or when the
// global registry hasn't been initialised (tests that stub
@@ -298,34 +298,32 @@ async fn handle_agent_run_turn(req: AgentTurnRequest) -> Result<AgentTurnRespons
origin,
crate::memory::scope::within_agent(
&memory_agent,
- with_file_state_agent_id(
- file_state_id,
- with_current_sandbox_mode(sandbox_mode, async {
- // Channel/CLI turns run through the tinyagents harness
- // (issue #4249); the legacy `run_tool_call_loop` is removed.
- // `on_progress` mirrors the harness event stream (tool
- // timeline, text deltas, cost footer) — production channel
- // dispatch always supplies it and now expects it live.
- // `on_delta` (raw Sender<String>) is superseded by
- // `on_progress` text deltas, so it's intentionally unused.
- let _ = (&provider_name, silent, &channel_name, on_delta);
- run_channel_turn_via_graph(
- turn_model_source.clone(),
- &mut history,
- tools_registry.clone(),
- extra_tools,
- visible_tool_names.as_ref(),
- &model,
- temperature,
- max_tool_iterations,
- multimodal.clone(),
- multimodal_files.clone(),
- on_progress,
- Some(graph_origin),
- )
- .await
- }),
- ),
+ with_file_state_agent_id(file_state_id, async {
+ // Channel/CLI turns run through the tinyagents harness
+ // (issue #4249); the legacy `run_tool_call_loop` is removed.
+ // `on_progress` mirrors the harness event stream (tool
+ // timeline, text deltas, cost footer) — production channel
+ // dispatch always supplies it and now expects it live.
+ // `on_delta` (raw Sender<String>) is superseded by
+ // `on_progress` text deltas, so it's intentionally unused.
+ let _ = (&provider_name, silent, &channel_name, on_delta);
+ run_channel_turn_via_graph(
+ turn_model_source.clone(),
+ &mut history,
+ tools_registry.clone(),
+ extra_tools,
+ visible_tool_names.as_ref(),
+ &model,
+ temperature,
+ max_tool_iterations,
+ multimodal.clone(),
+ multimodal_files.clone(),
+ on_progress,
+ Some(graph_origin),
+ sandbox_mode,
+ )
+ .await
+ }),
),
)
.await
diff --git a/crates/openhuman-core/src/agent/harness/graph.rs b/crates/openhuman-core/src/agent/harness/graph.rs
index 840649ddb3..2e875210a3 100644
--- a/crates/openhuman-core/src/agent/harness/graph.rs
+++ b/crates/openhuman-core/src/agent/harness/graph.rs
@@ -57,6 +57,7 @@ pub(crate) async fn run_channel_turn_via_graph(
multimodal_files: MultimodalFileConfig,
on_progress: Option<Sender<AgentProgress>>,
origin: Option<crate::agent::turn_origin::AgentTurnOrigin>,
+ sandbox_mode: crate::agent::harness::SandboxMode,
) -> Result<crate::agent::tinyagents::TinyagentsTurnOutcome> {
let extra_arc = Arc::new(extra_tools);
@@ -139,6 +140,7 @@ pub(crate) async fn run_channel_turn_via_graph(
let turn_origin = origin.clone();
let mut run_context = crate::agent::tinyagents::host::OpenHumanRunContext::new();
run_context.origin = origin;
+ run_context.sandbox_mode = Some(sandbox_mode);
run_context.workspace = attachment_workspace.map(tinytools::WorkspaceDescriptor::new);
seed_channel_attachments(&mut run_context, &prepared);
// The channel dispatcher owns this explicit sink. It wins over an embedder
diff --git a/crates/openhuman-core/src/agent/harness/graph_tests.rs b/crates/openhuman-core/src/agent/harness/graph_tests.rs
index 28edf2b14e..c7fc49fb19 100644
--- a/crates/openhuman-core/src/agent/harness/graph_tests.rs
+++ b/crates/openhuman-core/src/agent/harness/graph_tests.rs
@@ -63,6 +63,7 @@ async fn channel_turn_runs_through_the_graph() {
MultimodalFileConfig::default(),
None,
None,
+ crate::agent::harness::SandboxMode::None,
)
.await
.expect("channel graph turn runs");
@@ -124,6 +125,7 @@ async fn channel_turn_pauses_on_ask_user_clarification() {
MultimodalFileConfig::default(),
None,
None,
+ crate::agent::harness::SandboxMode::None,
)
.await
.expect("channel graph turn runs");
diff --git a/crates/openhuman-core/src/agent/harness/mod.rs b/crates/openhuman-core/src/agent/harness/mod.rs
index 399f357104..02a418961e 100644
--- a/crates/openhuman-core/src/agent/harness/mod.rs
+++ b/crates/openhuman-core/src/agent/harness/mod.rs
@@ -27,7 +27,6 @@ pub(crate) mod definition_loader;
pub mod fork_context;
pub(crate) mod graph;
pub(crate) mod memory_context_safety;
-pub mod sandbox_context;
pub(crate) mod spawn_depth_context;
pub(crate) mod tool_result_artifacts;
@@ -41,7 +40,6 @@ pub use definition::{
pub use fork_context::{
current_parent, with_parent_context, AgentContextPreparedSource, ParentExecutionContext,
};
-pub use sandbox_context::{current_sandbox_mode, with_current_sandbox_mode};
pub(crate) use spawn_depth_context::{with_spawn_depth, MAX_SPAWN_DEPTH};
pub(crate) use graph::run_channel_turn_via_graph;
diff --git a/crates/openhuman-core/src/agent/harness/sandbox_context.rs b/crates/openhuman-core/src/agent/harness/sandbox_context.rs
deleted file mode 100644
index cdbc696e77..0000000000
--- a/crates/openhuman-core/src/agent/harness/sandbox_context.rs
+++ /dev/null
@@ -1,63 +0,0 @@
-//! Task-local carrier for the **calling agent's `sandbox_mode`** so tool
-//! implementations can enforce sandbox semantics at execution time without
-//! widening the [`tinytools::Tool`] trait signature.
-//!
-//! Sibling of the existing [`super::fork_context`] task-local but serves
-//! a different concept: `PARENT_CONTEXT` carries the *parent agent's*
-//! runtime context so that `spawn_subagent` can inherit it, whereas
-//! [`CURRENT_AGENT_SANDBOX_MODE`] carries the *currently-executing
-//! agent's* sandbox mode so that any tool it invokes can gate on that
-//! mode.
-//!
-//! Why a task-local instead of an argument on [`Tool::execute`]: the tool
-//! trait is called from many places (CLI, JSON-RPC, tests, agent loops).
-//! Threading an optional context argument through every call site would
-//! touch every tool implementation and every caller. A task-local keeps
-//! the additive path scoped to the agent runtime that actually needs it.
-//!
-//! Tools read the current mode via [`current_sandbox_mode`]. When the
-//! task-local isn't set (direct CLI / JSON-RPC / unit-test invocation),
-//! the function returns `None` and tools fall through to their default
-//! pre-sandbox behavior, so this change is strictly additive.
-
-use super::definition::SandboxMode;
-
-tokio::task_local! {
- /// Sandbox mode declared in the currently-executing agent's
- /// `agent.toml`. Scoped per agent turn by the tool loop so any tool
- /// executed inside that turn can read it. `None` when unset (direct
- /// tool invocation outside an agent turn).
- pub static CURRENT_AGENT_SANDBOX_MODE: SandboxMode;
-}
-
-/// Returns the current agent's `sandbox_mode`, if the scope is active.
-///
-/// Returns `None` when called from outside
-/// [`with_current_sandbox_mode`] — e.g. CLI tool invocation, JSON-RPC
-/// tool dispatch, or unit tests that call a [`Tool`] directly.
-pub fn current_sandbox_mode() -> Option<SandboxMode> {
- CURRENT_AGENT_SANDBOX_MODE.try_with(|mode| *mode).ok()
-}
-
-/// Run `future` with `mode` installed as the current sandbox mode.
-///
-/// Intended call site is the tool loop (and subagent runner) immediately
-/// around each `tool.execute(args)` invocation so every tool the agent
-/// calls observes the correct mode. The scope does not leak into any
-/// detached task spawned inside `future` — that is standard
-/// [`tokio::task_local!`] semantics.
-pub async fn with_current_sandbox_mode<F, R>(mode: SandboxMode, future: F) -> R
-where
- F: std::future::Future<Output = R>,
-{
- // Box before `scope` so only a pointer moves into the task-local frame
- // rather than the whole nested turn generator — see the measurements on
- // the explicit usage ledger on `OpenHumanRunContext`.
- CURRENT_AGENT_SANDBOX_MODE
- .scope(mode, Box::pin(future))
- .await
-}
-
-#[cfg(test)]
-#[path = "sandbox_context_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/agent/harness/sandbox_context_tests.rs b/crates/openhuman-core/src/agent/harness/sandbox_context_tests.rs
deleted file mode 100644
index 7fd3d1ae50..0000000000
--- a/crates/openhuman-core/src/agent/harness/sandbox_context_tests.rs
+++ /dev/null
@@ -1,35 +0,0 @@
-use super::*;
-
-#[tokio::test]
-async fn current_sandbox_mode_returns_none_outside_scope() {
- assert_eq!(current_sandbox_mode(), None);
-}
-
-#[tokio::test]
-async fn with_current_sandbox_mode_installs_read_only() {
- let observed =
- with_current_sandbox_mode(SandboxMode::ReadOnly, async { current_sandbox_mode() }).await;
- assert_eq!(observed, Some(SandboxMode::ReadOnly));
-}
-
-#[tokio::test]
-async fn with_current_sandbox_mode_does_not_leak_across_scopes() {
- with_current_sandbox_mode(SandboxMode::ReadOnly, async {
- assert_eq!(current_sandbox_mode(), Some(SandboxMode::ReadOnly));
- })
- .await;
- assert_eq!(current_sandbox_mode(), None);
-}
-
-#[tokio::test]
-async fn nested_scope_overrides_outer() {
- with_current_sandbox_mode(SandboxMode::ReadOnly, async {
- assert_eq!(current_sandbox_mode(), Some(SandboxMode::ReadOnly));
- with_current_sandbox_mode(SandboxMode::Sandboxed, async {
- assert_eq!(current_sandbox_mode(), Some(SandboxMode::Sandboxed));
- })
- .await;
- assert_eq!(current_sandbox_mode(), Some(SandboxMode::ReadOnly));
- })
- .await;
-}
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.rs
index 95a33d95e2..2b2cc868e3 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
@@ -69,8 +69,10 @@ fn workspace_retention_leaves_legacy_project_artifacts_alone() {
build_artifact_store(&workspace, "current");
- assert!(stale.exists(), "project files are outside workspace retention");
+ 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");
}
-
diff --git a/crates/openhuman-core/src/agent/session_host/turn/graph.rs b/crates/openhuman-core/src/agent/session_host/turn/graph.rs
index 18e3b4f85d..4b6abdd1ff 100644
--- a/crates/openhuman-core/src/agent/session_host/turn/graph.rs
+++ b/crates/openhuman-core/src/agent/session_host/turn/graph.rs
@@ -28,7 +28,7 @@ use std::sync::Arc;
use anyhow::Result;
use tokio::sync::mpsc::Sender;
-use crate::agent::harness::{with_current_sandbox_mode, SandboxMode};
+use crate::agent::harness::SandboxMode;
use crate::agent::progress::AgentProgress;
use crate::agent::tinyagents::{
run_root_turn_via_hosted_agent, TinyagentsTurnOutcome, TurnContextMiddleware,
@@ -119,7 +119,7 @@ pub(crate) async fn run_chat_turn_graph(graph: ChatTurnGraph) -> Result<Tinyagen
// `TurnModelSource` (issue #4249, Phase 3 / Motion A); the telemetry id rides
// on the bundle.
let provider_id = graph.turn_models.provider_id().to_string();
- with_current_sandbox_mode(graph.sandbox_mode, async {
+ async {
let mut run_context = graph.run_context;
run_context.progress = graph.on_progress.clone().or(run_context.progress);
run_context.workspace = graph.workspace_descriptor.clone().or(run_context.workspace);
@@ -189,6 +189,6 @@ pub(crate) async fn run_chat_turn_graph(graph: ChatTurnGraph) -> Result<Tinyagen
defer_turn_completed_to_caller,
)
.await
- })
+ }
.await
}
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
index 77f60ac2d8..5c5c764c91 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -21,8 +21,7 @@ use crate::agent::harness::definition::{
};
use crate::agent::harness::fork_context::ParentExecutionContext;
use crate::agent::harness::{
- spawn_depth_context::current_spawn_depth, with_current_sandbox_mode, with_spawn_depth,
- MAX_SPAWN_DEPTH,
+ spawn_depth_context::current_spawn_depth, with_spawn_depth, MAX_SPAWN_DEPTH,
};
use crate::agent::prompts::{
render_subagent_system_prompt_with_format, PromptContext, SubagentRenderOptions,
@@ -338,7 +337,7 @@ pub(crate) async fn run_subagent_direct(
}
let run_result = Box::pin(with_spawn_depth(attempted_depth, async {
crate::memory::scope::within_agent(&definition.id, with_file_state_agent_id(task_id.clone(), async {
- with_current_sandbox_mode(definition.sandbox_mode, async {
+ async {
Box::pin(run_typed_mode(
definition,
task_prompt,
@@ -348,7 +347,7 @@ pub(crate) async fn run_subagent_direct(
&loaded_config,
))
.await
- })
+ }
.await
}))
.await
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index b862bb3a0c..62830f22f6 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -380,10 +380,14 @@ pub(crate) struct HostOperationContext {
/// 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> {
+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(|extension| {
+ extension.downcast_ref::<tinyagents_harness::tool::ToolExecutionContext>()
+ })
.and_then(|context| context.state::<HostOperationContext>())
.and_then(|host| host.sandbox_mode)
}
diff --git a/crates/openhuman-core/src/integrations/composio/action_tool.rs b/crates/openhuman-core/src/integrations/composio/action_tool.rs
index c9f279603d..1f898d7926 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::tinyagents::host::run_context::sandbox_mode_for_tool;
use crate::agent::harness::definition::SandboxMode;
+use crate::agent::tinyagents::host::run_context::sandbox_mode_for_tool;
use crate::config::rpc as config_rpc;
use crate::config::Config;
-use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult, ToolCallOptions, ToolRunContext};
+use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolCategory, ToolResult, ToolRunContext};
/// A single Composio action exposed as a first-class tool.
pub struct ComposioActionTool {
@@ -243,12 +243,15 @@ impl Tool for ComposioActionTool {
super::tools::redact_composio_outcome(&config, outcome)
}
async fn execute_with_context(
- &self, args: Value, _options: ToolCallOptions, context: Option<&dyn ToolRunContext>,
+ &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;
+ let (config, outcome) =
+ Box::pin(self.execute_unredacted(args, sandbox_mode_for_tool(context))).await;
super::tools::redact_composio_outcome(&config, outcome)
}
-
}
impl ComposioActionTool {
@@ -256,7 +259,11 @@ 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, sandbox_mode: Option<SandboxMode>) -> (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
diff --git a/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs b/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs
index 23aacb247a..c32bc201c3 100644
--- a/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/action_tool_tests.rs
@@ -135,9 +135,13 @@ fn sandbox_read_only_blocks_per_action_write_call() {
host.sandbox_mode = Some(SandboxMode::ReadOnly);
let run = host.into_tinyagents(tinyagents_harness::context::RunConfig::new("read-only"));
let context = tinyagents_harness::tool::ToolExecutionContext::from_run_context(
- &run, tinyagents_harness::ids::CallId::new("action"),
+ &run,
+ tinyagents_harness::ids::CallId::new("action"),
);
- let result = t.execute_with_context(serde_json::json!({}), Default::default(), Some(&context)).await.unwrap();
+ let result = t
+ .execute_with_context(serde_json::json!({}), Default::default(), Some(&context))
+ .await
+ .unwrap();
assert!(
result.is_error,
"per-action Write under read-only must error"
@@ -161,9 +165,13 @@ fn sandbox_read_only_blocks_per_action_admin_call() {
host.sandbox_mode = Some(SandboxMode::ReadOnly);
let run = host.into_tinyagents(tinyagents_harness::context::RunConfig::new("read-only"));
let context = tinyagents_harness::tool::ToolExecutionContext::from_run_context(
- &run, tinyagents_harness::ids::CallId::new("action"),
+ &run,
+ tinyagents_harness::ids::CallId::new("action"),
);
- let result = t.execute_with_context(serde_json::json!({}), Default::default(), Some(&context)).await.unwrap();
+ let result = t
+ .execute_with_context(serde_json::json!({}), Default::default(), Some(&context))
+ .await
+ .unwrap();
assert!(result.is_error);
let msg = error_text(&result);
assert!(msg.contains("`admin`"), "got: {msg}");
@@ -487,7 +495,8 @@ 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!({}), None)).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.rs
index f9db002725..eb0f94ef50 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::tinyagents::host::run_context::sandbox_mode_for_tool;
use crate::agent::harness::definition::SandboxMode;
+use crate::agent::tinyagents::host::run_context::sandbox_mode_for_tool;
use crate::config::Config;
use crate::integrations::composio::task_recency_context::current_task_recency_window;
-use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult, ToolCallOptions, ToolRunContext};
+use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolCategory, ToolResult, ToolRunContext};
use super::super::ops::load_user_scope_pref;
use super::super::providers::{toolkit_from_slug, ToolScope};
@@ -104,12 +104,15 @@ impl Tool for ComposioExecuteTool {
redact_composio_outcome(&config, outcome)
}
async fn execute_with_context(
- &self, args: Value, _options: ToolCallOptions, context: Option<&dyn ToolRunContext>,
+ &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;
+ let (config, outcome) =
+ Box::pin(self.execute_unredacted(args, sandbox_mode_for_tool(context))).await;
redact_composio_outcome(&config, outcome)
}
-
}
impl ComposioExecuteTool {
@@ -117,7 +120,11 @@ 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, sandbox_mode: Option<SandboxMode>) -> (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())
diff --git a/crates/openhuman-core/src/integrations/composio/tools_metadata_and_sandbox_tests.rs b/crates/openhuman-core/src/integrations/composio/tools_metadata_and_sandbox_tests.rs
index c9f9538565..72f17eb302 100644
--- a/crates/openhuman-core/src/integrations/composio/tools_metadata_and_sandbox_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools_metadata_and_sandbox_tests.rs
@@ -378,11 +378,11 @@ fn agent_tools_register_when_direct_mode_with_stored_key_and_no_backend_session(
#[tokio::test]
async fn sandbox_read_only_blocks_write_scope_action() {
let t = ComposioExecuteTool::new(fake_config_arc());
- let result = crate::agent::harness::with_current_sandbox_mode(SandboxMode::ReadOnly, async {
- t.execute(serde_json::json!({ "tool": "GMAIL_SEND_EMAIL" }))
- .await
- .unwrap()
- })
+ let result = execute_in_agent_mode(
+ &t,
+ serde_json::json!({ "tool": "GMAIL_SEND_EMAIL" }),
+ SandboxMode::ReadOnly,
+ )
.await;
assert!(
result.is_error,
@@ -396,11 +396,11 @@ async fn sandbox_read_only_blocks_write_scope_action() {
#[tokio::test]
async fn sandbox_read_only_blocks_admin_scope_action() {
let t = ComposioExecuteTool::new(fake_config_arc());
- let result = crate::agent::harness::with_current_sandbox_mode(SandboxMode::ReadOnly, async {
- t.execute(serde_json::json!({ "tool": "GMAIL_DELETE_EMAIL" }))
- .await
- .unwrap()
- })
+ let result = execute_in_agent_mode(
+ &t,
+ serde_json::json!({ "tool": "GMAIL_DELETE_EMAIL" }),
+ SandboxMode::ReadOnly,
+ )
.await;
assert!(result.is_error);
let msg = error_text(&result);
@@ -432,11 +432,11 @@ async fn sandbox_read_only_passes_through_read_scope_actions_to_downstream_gates
config.save().await.expect("save fake config to disk");
let t = ComposioExecuteTool::new(Arc::new(config));
- let result = crate::agent::harness::with_current_sandbox_mode(SandboxMode::ReadOnly, async {
- t.execute(serde_json::json!({ "tool": "GMAIL_FETCH_EMAILS" }))
- .await
- .unwrap()
- })
+ let result = execute_in_agent_mode(
+ &t,
+ serde_json::json!({ "tool": "GMAIL_FETCH_EMAILS" }),
+ SandboxMode::ReadOnly,
+ )
.await;
let msg = error_text(&result);
assert!(
@@ -447,7 +447,7 @@ async fn sandbox_read_only_passes_through_read_scope_actions_to_downstream_gates
#[tokio::test]
async fn sandbox_unset_leaves_all_scopes_to_downstream_gates() {
- // Outside any `with_current_sandbox_mode` scope the task-local
+ // Without an explicit agent context there is no agent-specific mode; the tool
// returns `None` and the gate becomes a no-op (backward
// compatible — this is the CLI / JSON-RPC / unit-test path).
//
@@ -503,11 +503,11 @@ async fn sandbox_sandboxed_mode_does_not_trigger_readonly_gate() {
config.save().await.expect("save fake config to disk");
let t = ComposioExecuteTool::new(Arc::new(config));
- let result = crate::agent::harness::with_current_sandbox_mode(SandboxMode::Sandboxed, async {
- t.execute(serde_json::json!({ "tool": "GMAIL_SEND_EMAIL" }))
- .await
- .unwrap()
- })
+ let result = execute_in_agent_mode(
+ &t,
+ serde_json::json!({ "tool": "GMAIL_SEND_EMAIL" }),
+ SandboxMode::Sandboxed,
+ )
.await;
let msg = error_text(&result);
assert!(
@@ -686,3 +686,21 @@ fn empty_uncurated_toolkits_message_ignores_catalogued_toolkits() {
assert!(empty_uncurated_toolkits_message(&["gmail".to_string()]).is_none());
assert!(empty_uncurated_toolkits_message(&["googlesheets".to_string()]).is_none());
}
+
+/// Builds the same typed operation carrier the harness passes to real tools.
+async fn execute_in_agent_mode(
+ tool: &dyn Tool,
+ args: serde_json::Value,
+ mode: SandboxMode,
+) -> tinytools::ToolResult {
+ let mut host = crate::agent::tinyagents::host::OpenHumanRunContext::new();
+ host.sandbox_mode = Some(mode);
+ let run = host.into_tinyagents(tinyagents_harness::context::RunConfig::new("composio-test"));
+ let context = tinyagents_harness::tool::ToolExecutionContext::from_run_context(
+ &run,
+ tinyagents_harness::ids::CallId::new("execute"),
+ );
+ tool.execute_with_context(args, Default::default(), Some(&context))
+ .await
+ .unwrap()
+}
diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rs
index 38c3a1deca..784f0b7832 100644
--- a/crates/openhuman-core/src/sandbox/ops.rs
+++ b/crates/openhuman-core/src/sandbox/ops.rs
@@ -64,10 +64,7 @@ pub async fn command_requires_sandbox(sandbox_mode: Option<SandboxMode>) -> Resu
if sandbox_disabled_by_host() {
return Ok(false);
}
- if matches!(
- sandbox_mode,
- Some(SandboxMode::Sandboxed)
- ) {
+ if matches!(sandbox_mode, Some(SandboxMode::Sandboxed)) {
return Ok(true);
}
let config = crate::config::ops::load_config_with_timeout().await?;
diff --git a/crates/openhuman-core/src/skills/e2e_plumbing_tests.rs b/crates/openhuman-core/src/skills/e2e_plumbing_tests.rs
index a77bb87501..97fce00609 100644
--- a/crates/openhuman-core/src/skills/e2e_plumbing_tests.rs
+++ b/crates/openhuman-core/src/skills/e2e_plumbing_tests.rs
@@ -209,6 +209,7 @@ async fn mock_llm_orchestrator_lists_and_runs_workflows_through_the_loop() {
MultimodalFileConfig::default(),
None,
None,
+ crate::agent::harness::SandboxMode::None,
)
.await
.expect("tool loop should run to completion");
diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rs
index 4b2f3141d8..be9fe70fba 100644
--- a/crates/openhuman-core/src/tools/impl/system/shell.rs
+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs
@@ -328,7 +328,11 @@ 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(crate::agent::tinyagents::host::run_context::sandbox_mode_for_tool(context)).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 (
diff --git a/crates/openhuman-core/src/tools/rules/ops.rs b/crates/openhuman-core/src/tools/rules/ops.rs
index 39f612fcf6..395f991ad8 100644
--- a/crates/openhuman-core/src/tools/rules/ops.rs
+++ b/crates/openhuman-core/src/tools/rules/ops.rs
@@ -176,6 +176,7 @@ impl crate::agent::tinyagents::host::OpenHumanRunContext {
pub(crate) fn for_subagent(&self, def: &AgentDefinition, config: Option<&Config>) -> Self {
let mut child = self.clone();
child.tool_rules = child_rule_policy(self.tool_rules.as_deref(), config, def);
+ child.sandbox_mode = Some(def.sandbox_mode);
child
}
}