Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
let hosted_base = hosted_base.clone();
let mut run_context = run_context;
run_context.workspace = self.workspace.clone().or(run_context.workspace);
run_context.sandbox_mode = Some(self.sandbox_mode);
run_context.set_definition_sandbox_mode(self.sandbox_mode);
run_context.sandbox_filesystem_only = self.sandbox_filesystem_only;
run_context.browser_view_only |= self.browser_view_only;
let provider_id = turn_models.provider_id().to_string();
Expand Down
5 changes: 1 addition & 4 deletions crates/openhuman-core/src/agent/tinyagents/host/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ impl OpenHumanHostBundleFactory {
.with_dispatch(turn.dispatch_ctx())
.with_headless_descendant_settlement(turn.headless_descendant_settlement)
.with_scheduled_actions(turn.scheduled_actions)
.with_sandboxed_shell(matches!(
turn.sandbox_mode,
Some(tinyagents_definition::SandboxMode::Sandboxed)
));
.with_sandboxed_shell(turn.shell_jailed());
if let Some(policy) = inputs.tool_policy {
security = security.with_tool_policy(policy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ pub(crate) fn task_recency_window_for_tool(
window
}

/// Sandbox requirements a run keeps from the runs above it, whatever its own
/// definition says. Each one is only ever raised: a sub-agent starts with its
/// parent's and adds the parent's own mode
/// ([`OpenHumanRunContext::set_definition_sandbox_mode`](super::OpenHumanRunContext::set_definition_sandbox_mode)).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) struct InheritedSandbox {
/// A run above this one jails its shell, so this run's shell is jailed too.
pub(crate) shell_jail: bool,
}

/// Minimal immutable authority view exposed to shared tools through the
/// harness's typed state-view seam.
#[derive(Clone, Debug, Default)]
Expand All @@ -97,6 +107,8 @@ pub(crate) struct HostOperationContext {
/// [`OpenHumanRunContext::approval`](super::OpenHumanRunContext::approval).
pub(crate) approval: crate::security::approval::ApprovalTurnContext,
pub(crate) sandbox_mode: Option<SandboxMode>,
/// What the run keeps from the runs above it; see [`InheritedSandbox`].
pub(crate) inherited_sandbox: InheritedSandbox,
/// Whether the run's definition opted its sandboxed shell into a files-only jail.
pub(crate) sandbox_filesystem_only: bool,
/// Whether the run's browser is view-only (`AgentExt::browser_view_only`).
Expand Down Expand Up @@ -207,6 +219,27 @@ pub(crate) fn sandbox_mode_for_tool(
.and_then(|host| host.sandbox_mode)
}

/// The sandbox mode the shell runs a command under: `Sandboxed` when a run
/// above this one jails its shell ([`InheritedSandbox::shell_jail`]), else the
/// run's own. Direct tool dispatch has no agent-specific mode.
pub(crate) fn shell_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| {
if host.inherited_sandbox.shell_jail {
Some(SandboxMode::Sandboxed)
} else {
host.sandbox_mode
}
})
}

/// Whether the run's own definition opted its sandboxed shell into a files-only
/// jail (`AgentExt::sandbox_filesystem_only`). Direct tool dispatch never has.
pub(crate) fn sandbox_filesystem_only_for_tool(
Expand Down
10 changes: 8 additions & 2 deletions crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,13 @@ pub struct OpenHumanRunContext {
/// Autonomous skill-run iteration cap lifted onto every sub-agent in the
/// tree (inherited by `child()` through the clone); `None` for ordinary turns.
pub autonomous_iter_cap: Option<usize>,
/// Sandbox mode of the agent definition executing this turn.
/// Sandbox mode of the agent definition executing this turn. Set through
/// [`Self::set_definition_sandbox_mode`], which keeps what the runs above
/// required in [`Self::inherited_sandbox`].
pub sandbox_mode: Option<SandboxMode>,
/// Sandbox requirements kept from the runs above this one; only ever
/// raised, and copied to a child by `child()`.
pub(crate) inherited_sandbox: InheritedSandbox,
/// The definition executing this turn opted its sandboxed shell into a
/// files-only jail (`AgentExt::sandbox_filesystem_only`). Set from the
/// definition for a session's root run; `child()` copies the parent's value
Expand Down Expand Up @@ -442,7 +447,8 @@ pub(crate) use super::operation_context::{
browser_view_only_for_tool, command_environment_for_tool, dispatch_ctx_for_tool,
memory_identity_for_tool, memory_in_prompt_for_tool, parent_agent_id_for_tool,
sandbox_filesystem_only_for_tool, sandbox_mode_for_tool, shell_processes_for_tool,
task_recency_window_for_tool, turn_origin_for_tool, HostOperationContext,
shell_sandbox_mode_for_tool, task_recency_window_for_tool, turn_origin_for_tool,
HostOperationContext, InheritedSandbox,
};
#[cfg(test)]
pub(crate) use super::operation_context::{test_turn_run, tool_context_with_approval};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl OpenHumanRunContext {
command_environment: None,
autonomous_iter_cap: None,
sandbox_mode: None,
inherited_sandbox: InheritedSandbox::default(),
sandbox_filesystem_only: false,
browser_view_only: false,
spawn_depth: 0,
Expand Down Expand Up @@ -225,6 +226,31 @@ impl OpenHumanRunContext {
self
}

/// Sets the sandbox mode of the definition now executing this run. What
/// the mode being replaced required is kept in `inherited_sandbox`, so a
/// sub-agent never runs looser than its parent, whatever its own mode.
pub(crate) fn set_definition_sandbox_mode(&mut self, mode: SandboxMode) {
let previous = self.sandbox_mode;
if matches!(self.sandbox_mode, Some(SandboxMode::Sandboxed)) {
self.inherited_sandbox.shell_jail = true;
}
self.sandbox_mode = Some(mode);
tracing::debug!(
?previous,
?mode,
inherited_shell_jail = self.inherited_sandbox.shell_jail,
spawn_depth = self.spawn_depth,
"[run_context] set_definition_sandbox_mode"
);
}

/// Whether this run's shell commands are jailed: by its own mode or by a
/// run above it.
pub(crate) fn shell_jailed(&self) -> bool {
self.inherited_sandbox.shell_jail
|| matches!(self.sandbox_mode, Some(SandboxMode::Sandboxed))
}

/// Makes this run's browser view-only when `definition` asks for it
/// (`AgentExt::browser_view_only`). Never clears it: a run already
/// view-only, such as the child of a view-only parent, stays so.
Expand Down Expand Up @@ -318,6 +344,7 @@ impl OpenHumanRunContext {
origin: self.origin.clone(),
approval: self.approval.clone(),
sandbox_mode: self.sandbox_mode,
inherited_sandbox: self.inherited_sandbox,
sandbox_filesystem_only: self.sandbox_filesystem_only,
browser_view_only: self.browser_view_only,
parent_agent_id: self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ pub struct OpenHumanSecurityGate {
/// `TrustedAutomationSource::CronActions` origin and a run depth of 0 or 1
/// it lifts the read-only Cron stage; every later stage still applies.
scheduled_actions: bool,
/// The run's sandbox mode is `Sandboxed`, so its shell commands run inside
/// The run's shell is jailed (`OpenHumanRunContext::shell_jailed`: its own
/// mode is `Sandboxed`, or a run above it is), so its commands run inside
/// the kernel jail and TinySecurity's lexical protected-path floor is
/// waived for them (`SecurityPolicy::check_jailed_command`). The shell
/// re-checks at execution and refuses again if the command would land on
Expand Down Expand Up @@ -190,8 +191,8 @@ impl OpenHumanSecurityGate {
}
}

/// Marks the gate as a run whose shell is jailed (its definition's sandbox
/// mode is `Sandboxed`).
/// Marks the gate as a run whose shell is jailed
/// (`OpenHumanRunContext::shell_jailed`).
pub(crate) fn with_sandboxed_shell(mut self, enabled: bool) -> Self {
self.sandboxed_shell = enabled;
self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ pub(super) async fn drive_turn(
// Only a child the sub-agent runner granted scheduled actions
// carries the mark (`subagent_host::ops::scheduled_actions_grant`).
.with_scheduled_actions(run_context.scheduled_actions)
.with_sandboxed_shell(matches!(
run_context.sandbox_mode,
Some(tinyagents_definition::SandboxMode::Sandboxed)
));
.with_sandboxed_shell(run_context.shell_jailed());
if let Some(policy) = tool_policy.as_ref() {
gate = gate.with_tool_policy(Arc::new(policy.session.clone()));
}
Expand Down
7 changes: 7 additions & 0 deletions crates/openhuman-core/src/agent_registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ own definition sets the flag or its parent run is view-only, and a child cannot
clear it (unlike `sandbox_filesystem_only`, a child's own `true` counts).
Default `false`.

A sub-agent runs under its own definition's `sandbox_mode`, but its shell is
never looser than its parent's: under a run whose shell is jailed (its own
`sandbox_mode = "sandboxed"`, or a run above it), a child's shell commands run
in the jail too, whatever the child's own mode. The child's mode still applies
to everything else, so a `read_only` child stays read-only. The run context
keeps this in `inherited_sandbox`.

## Called by

- `core/all.rs`: registers the `agent_registry` controllers under
Expand Down
30 changes: 15 additions & 15 deletions crates/openhuman-core/src/tools/impl/system/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,12 @@ impl ShellTool {
// A run whose sandbox mode is `Sandboxed` always takes the sandbox
// path below (`should_plan_command`), so its command is jailed unless
// the plan resolves it to the host; `run_in_policy` refuses that case.
// Both decisions read this one mode, which includes a jail kept from a
// parent run.
let sandbox_mode =
crate::agent::tinyagents::host::run_context::shell_sandbox_mode_for_tool(context);
let jailed = matches!(
crate::agent::tinyagents::host::run_context::sandbox_mode_for_tool(context),
sandbox_mode,
Some(tinyagents_definition::SandboxMode::Sandboxed)
);
let floor_waived = match self.check_for_execution(command, jailed).await {
Expand Down Expand Up @@ -358,20 +362,16 @@ 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::policy::should_plan_command(
ctx,
crate::agent::tinyagents::host::run_context::sandbox_mode_for_tool(context),
)
.await
{
Ok(required) => required,
Err(err) => {
return (
false,
ToolResult::error(format!("Cannot read sandbox configuration: {err}")),
);
}
};
let sandbox_required =
match crate::sandbox::policy::should_plan_command(ctx, sandbox_mode).await {
Ok(required) => required,
Err(err) => {
return (
false,
ToolResult::error(format!("Cannot read sandbox configuration: {err}")),
);
}
};
if sandbox_required {
let action_dir = self.effective_action_dir_for_context(context);
let timeout = requested_timeout;
Expand Down
3 changes: 2 additions & 1 deletion crates/openhuman-core/src/tools/rules/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ 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);
// The child's own mode, never looser than its parent's.
child.set_definition_sandbox_mode(def.sandbox_mode);
// Kept from the parent, and raised by the child's own definition.
child.tighten_browser_view_only(Some(def));
child
Expand Down
Loading
Loading