openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Sandboxed shell in a cron agent job is always refused (denial=Path) when workspace_dir is inside action_dir; no per-job sandbox root

Open senamakel opened this issue 3 weeks ago • 1 comments

Summary

A cron agent job whose definition sets sandbox_mode = "sandboxed" cannot run a single shell command when the core's workspace_dir lies inside action_dir. Every call is refused before any executor is picked:

WRN:spawn_plan [sandbox:plan] the module refused the spawn denial=Path
Sandbox execution failed: Sandbox plan refused: the sandbox plan was refused (Path)

The refusal is correct. The gap is that a scheduled agent has no way to get a narrower sandbox root than the process-wide action_dir.

Seen on a production deployment (openhuman pin 83f6602153, tinysecurity v0.20.0): OPENHUMAN_ACTION_DIR=/srv/teeny (a checkout whose cron shell jobs are bin/... relative to it), OPENHUMAN_WORKSPACE=/srv/teeny/brain. The native jail is available (config_get_sandbox_settings → detected_backend: landlock). A builder agent run by a cron job failed shell 7 times in a row with different commands. file_read in the same run worked.

Trace

  1. ShellTool::run_sandboxed builds the policy from the run's action dir: crates/openhuman-core/src/tools/impl/system/shell.rs:612 (route_for_mode). The action dir comes from effective_action_dir_for_context (shell.rs:113), which is security.action_dir unless the run carries a WorkspaceDescriptor.
  2. sandbox/policy.rs:78 sets workspace_root: action_dir. spawn_plan/facts.rs:124 (grant_ceiling) asks for it read-write.
  3. TinySecurity admits grants before choosing an executor: tinysecurity-sandbox/src/engine.rs:489 → grants::admit → PathScope::validate_grant. In tinysecurity-policy/src/path_subtree.rs:104, subtree_restricted refuses any root that overlaps(root, &self.workspace_dir). Then tinysecurity-sandbox/src/grants.rs:25 returns SandboxDenial2::Path.
  4. facts.rs:182 already states this behaviour ("a grant that overlaps workspace_dir is still refused"). Granting a jail RW over a tree that contains the core's state, secrets and code should be refused. It is not the bug.

The gap

Every sandboxed shell spawn is rooted at one directory: the process-wide action_dir, or a WorkspaceDescriptor on the run. Interactive paths can set a descriptor (sub-agent worktrees, agent.chat's cwd). A cron agent job cannot: CronJob (tinyflows-bus schedule/types.rs) has no root field, the agent definition has none, and cron/scheduler/agent_run.rs never calls RunContext::with_workspace. Cron shell jobs need action_dir to be the checkout (cron/scheduler/shell_job.rs:79 runs them there), so the operator cannot move action_dir without breaking every shell job.

So a deployment that keeps the core workspace under its action dir can never use sandbox_mode = "sandboxed" from cron. The refusal (Path) also does not say which grant failed or why.

Proposed fix

  • Let a cron agent job carry a workspace root, either a workspace/cwd field on the agent job or an operator-trusted field on the agent definition. Thread it into the run as a WorkspaceDescriptor (RunContext::with_workspace, agent/tinyagents/host/run_context/behavior.rs:123), the way agent.chat's cwd does. security_for_tool_context and effective_action_dir_for_context then root the file tools and the shell there, and the sandbox grant becomes that directory. It must exist and must not overlap workspace_dir (same checks as agent.chat cwd).
  • Optional: when the policy's workspace_root overlaps workspace_dir, fail with a clear host-side message (for example "the action dir contains the core workspace; sandboxed shell needs a separate root") rather than an opaque Path denial. A boot-time warning when sandbox_mode = "sandboxed" agents exist and action_dir ⊇ workspace_dir would also help.

Regression test idea

Configure workspace_dir = <root>/brain, action_dir = <root>, and a cron agent job with a sandboxed definition rooted at <root>/work/job. Assert the spawn plans with exactly one RW grant, <root>/work/job. Today it is refused with Path.

senamakel avatar Nov 12 '26 02:11 senamakel

Cron agent jobs have no way to supply a per-job sandbox root, so when workspace_dir is inside action_dir every sandboxed shell spawn is refused with an opaque Path denial; the request is to thread a workspace/cwd root into cron agent runs as a WorkspaceDescriptor and improve the diagnostics. No candidate reports the same problem.

Labelled priority: p2.

tinysweeper avatar Nov 12 '26 02:11 tinysweeper