Repository navigation
feat(security): let a kernel-sandboxed agent shell rely on its jail - #8776
Conversation
Refused shell commands are now budgeted per command rather than per run, so tests assert that distinct commands keep the turn alive while a repeated command or a second block on another tool still halts it. A new scope test also checks that shell failure scopes fingerprint the command without persisting its text. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add a `protected_class` hook to `CommandGateway` and a `protected_command_class` helper on `SecurityPolicy` that reports the command class when the only refusal came from the protected-path floor. This lets callers distinguish floor-only refusals from other denials without changing existing refusal behaviour. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Introduce a jailed_commands module under the security policy with test support exposing a floor policy and gateway, and wire it into the policy module so tests can exercise command jailing behaviour. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Adds unit tests covering the jailed command policy so its allow and deny behaviour is verified. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The security gate now knows whether a run's shell is jailed and, when it is, authorizes commands through check_jailed_command so only the lexical protected-path floor is waived while every other refusal still applies. The shell re-checks at execution and refuses if the command would land on the host. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add tests asserting that a shell running in the kernel jail is allowed to name protected paths such as `..` or `/etc/os-release`, while an unsandboxed shell still hits the protected-path floor and a read-only autonomy level still refuses writes. This pins the behaviour that motivated the fix. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
A command admitted only because it would run in the jail now gets refused when it resolves to the host backend, since the protected-path floor is the only boundary left there. Added a helper for the check and tests covering the refusal and the backends it does not apply to. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
…ants Execution-stage admission now distinguishes jailed commands from host ones, so a command admitted for the sandbox no longer answers to the lexical protected-path floor and is refused outright if it would fall through to the host. The sandbox path also resolves the operator's `[runtime.local_jail]` grants before planning, falling back to the workspace-only jail if they are unavailable. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The shell tool now resolves local jail grants only when the sandbox backend is the native local jail, leaving container and box policies untouched. This avoids applying local-only grant resolution to backends that manage their own boundaries, with tests covering the protected-path floor at execution. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Moved the `[runtime.local_jail]` grant resolution out of the shell tool into a `with_jail_grants` helper in `shell_run`, so the logic sits with the rest of the spawn-plan handling and can be tested directly. Added a test covering extra read-only and read-write grants reaching a jailed shell and floor grants being dropped. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
…rants The security policy README now explains how shell commands running inside the kernel sandbox are checked with the protected-path floor waived while every other refusal is kept, and the sandbox and cron READMEs describe how local jail grants are resolved and admitted. The approval-gate page was corrected to match. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Removed the unused `FloorGateway` re-export from the policy module's test-only imports, leaving only `floor_policy`. This trims a stale import that no longer has any consumers. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Shell failures now use a fingerprint of the command as their failure scope, so a refusal of one command no longer shares a budget with an unrelated one. Blocked shell commands also get a few retries before the turn stops, since previously any two refused commands in a run ended it. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Shell policy refusals now share a wider class budget that a successful command resets, so unrelated refused commands no longer end the run together. The same command refused unchanged three times still stops the turn, tracked per run by command fingerprint. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The assess implementation now takes the run context instead of ignoring it, so the refused command budget can be computed from the instance id. This removes the unused parameter and lets the policy apply per-instance budget logic. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Read-only refusals now get a single retry instead of the wider shell budget, since every acting command is refused alike in that mode. The same refused command now stops the turn on its second refusal, and a dedicated nudge tells the model to try a different permitted command rather than resending the same one. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Reworded the shell refusal nudge to tell the model to try a different, narrower, permitted command, making the guidance clearer when a command is blocked by policy. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Include the command output in the assertion message so a failing jail check shows what the command actually returned, making the failure easier to diagnose. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Reformatted several security policy test files to satisfy rustfmt line-length rules and reordered the re-exports in the policy module so the jailed-commands items sit together. No behaviour changed. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The protected-path floor tests for jailed shells were extracted from the main security gate test file into a dedicated module, keeping the growing test suite organised without changing what the tests cover. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Caution Review failedThe pull request is closed. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
🟡 Changes recommended
The adapter authorizes rewritten shell text rather than the command that will execute, violating the security contract, while real-module waiver behavior and host-fallback enforcement lack integration coverage.
3 open issues
What changed in this PR
This PR adjusts OpenHuman’s sandboxed agent shell to rely on jail isolation for protected paths, while retaining other security checks and guards against unjailed execution.
Changes:
- Expands the retry budget for different refused shell commands while stopping repeated identical refusals.
- Adds sandbox-aware command admission at authorization and execution, with a host-fallback refusal.
- Forwards configured local-jail grants and adds focused tests and documentation.
| File | Description |
|---|---|
docs/gitbooks/en/features/approval-gate.md |
Documents the sandboxed-shell floor exception. |
crates/openhuman-core/src/tools/impl/system/shell.rs |
Adds jailed execution checks and grant forwarding. |
crates/openhuman-core/src/tools/impl/system/shell_tests_runtime_and_sandbox_tests.rs |
Tests execution-stage admission and refusals. |
crates/openhuman-core/src/tools/impl/system/shell_run.rs |
Adds host-fallback refusal and local-jail grants. |
crates/openhuman-core/src/tools/impl/system/shell_run_tests.rs |
Tests fallback helper and grant propagation. |
crates/openhuman-core/src/security/policy/README.md |
Explains jailed command admission. |
crates/openhuman-core/src/security/policy/native_commands.rs |
Retrieves classes for protected-path refusals. |
crates/openhuman-core/src/security/policy/mod.rs |
Registers jailed-command support. |
crates/openhuman-core/src/security/policy/jailed_commands/test_support.rs |
Adds a scripted command gateway for tests. |
crates/openhuman-core/src/security/policy/jailed_commands.rs |
Implements the floor waiver and text neutralization. |
crates/openhuman-core/src/security/policy/jailed_commands_tests.rs |
Tests waiver behavior and retained restrictions. |
crates/openhuman-core/src/sandbox/README.md |
Documents local-jail grant propagation. |
crates/openhuman-core/src/cron/README.md |
Clarifies sandboxed cron shell behavior. |
crates/openhuman-core/src/agent/tinyagents/turn_exec/drive.rs |
Passes sandbox mode into the security gate. |
crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs |
Tracks repeated refusals by command. |
crates/openhuman-core/src/agent/tinyagents/middleware/failure_policy.rs |
Expands shell refusal budgets and guidance. |
crates/openhuman-core/src/agent/tinyagents/middleware_failure_policy_class_tests.rs |
Tests distinct and repeated command refusals. |
crates/openhuman-core/src/agent/tinyagents/host/security_gate/authorize.rs |
Uses jailed admission for sandboxed shells. |
crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs |
Adds sandboxed-shell gate configuration. |
crates/openhuman-core/src/agent/tinyagents/host/security_gate_tests.rs |
Registers jailed-shell tests. |
crates/openhuman-core/src/agent/tinyagents/host/security_gate_jailed_shell_tests.rs |
Tests sandbox-aware authorization. |
crates/openhuman-core/src/agent/tinyagents/host/bundle.rs |
Configures the gate from the turn’s sandbox mode. |
Review effort: Balanced
| let verdict = self | ||
| .check_command(CommandQuery { | ||
| command: &neutral, | ||
| declared, | ||
| ..query |
There was a problem hiding this comment.
Partly addressed in 52fcd0c: the neutralized text no longer drops the command word or env-assignment names (e.g. GIT_PAGER=../pager git log -> GIT_PAGER=x git log), so command-sensitive checks still see them. Not done here: forwarding the exact original command with a trusted sandbox context requires a new jailed-admission operation in the TinySecurity contract and a new module release/gitlink. That is an upstream change outside this PR; leaving the thread open as the tracked follow-up.
| (decision.denial == Some(tinysecurity_bus::CommandDenial::Protected)) | ||
| .then(|| from_bus_class(decision.class)) |
There was a problem hiding this comment.
Valid gap: the jailed-command tests use FloorGateway, so they do not exercise the pinned module's Classify response. Not added in this change; a smoke test through the pinned module is a follow-up. Leaving open.
| if let Some(refusal) = unjailed_floor_refusal(floor_waived, resolved.backend()) { | ||
| return (false, refusal); |
There was a problem hiding this comment.
Valid gap: host fallback is covered at the helper level (unjailed_floor_refusal, now also the macOS Seatbelt case) and by the guard in run_in_policy, but not by an end-to-end host-plan test asserting no process launched. Not added in this change; leaving open.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 434f80f4dc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .check_command(CommandQuery { | ||
| command: &neutral, | ||
| declared, | ||
| ..query | ||
| }) |
There was a problem hiding this comment.
Put the floor waiver behind TinySecurity's bus contract
check_jailed_command now interprets a TinySecurity Protected decision, rewrites the command, and decides whether a second verdict should supersede the first, which is a command/path-policy algorithm rather than host configuration or execution orchestration. The repository explicitly requires missing loadable-module behavior to be added to the owning contract and implementation instead of introducing a host-side workaround; add a jailed-command operation or sandbox context to tinysecurity-bus/TinySecurity and keep this crate as the adapter that passes context and executes the returned decision.
AGENTS.md reference: AGENTS.md:L571-L574
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed on the design. This PR keeps the waiver as a thin host adapter that fails closed (any refusal other than the floor stays, an un-neutralizable command stays refused, host and macOS Seatbelt runs refuse). Moving the algorithm into tinysecurity-bus needs an upstream contract and release first; left open as the follow-up rather than done in this PR.
fix(shell): follow-ups to #8776 that missed the merge


Summary
An autonomous cron agent defined with
scheduled_actions = true,sandbox_mode = "sandboxed"andsandbox_filesystem_only = trueruns its shell inside the kernel jail (Landlock / bubblewrap through TinyBox), which grants only its own folder. In production its runs died within minutes because of three host-side behaviours that add nothing once the jail is in place. This PR loosens those three. The secrets directory and the core's own keyring and config stay closed. The jail's grants, its credential deny list and the file-tool reservations keep them closed. The lexical floor never did that job.1. Two refused shell commands ended the run
Symptom: the second
[policy-blocked]shell result in a run, whatever the two commands were, ended it with "I stopped this turn early because a step this needs is blocked by your security settings."Cause:
blocked_by_policyhad a budget of 1, and the ledger scopes every shell failure as justshell.Change (
agent/tinyagents/middleware/failure_policy.rs,repeated_failure.rs):SHELL_REFUSAL_BUDGET = 8refusals of different commands, and any command that runs resets the count.SAME_REFUSED_COMMAND_LIMIT = 2, tracked per run and cleared infinish_run).Why the scope was not changed: I first scoped the shell failure ledger by command. That also split the deliberate shared budgets for shell timeouts (
uncertain_side_effect) and missing programs (missing_app). Their tests use different commands on purpose: a corrected command is still a retry of the same step. The ledger scope is computed before the result is classified, so it cannot vary by failure class. The budget and the per-command repeat check get the same effect for policy refusals only.2. A lexical "protected path" floor refused ordinary commands inside the jail
Symptom:
cd ..,sed 's/../X/'andcat /etc/os-releasewere refused with "Command references a protected path". TinySecurity's floor refuses any command whose text contains a..segment,/etc,/procor a credential-store name, at both the security gate (Authorize) and inside the shell tool (Execute). No tier or flag skipped it.Change:
SecurityPolicy::check_jailed_command(new,security/policy/jailed_commands.rs) waives onlyRefusal::Protected, and only for the harness flow.x(quotes,$, backticks and parentheses are kept) and the original class declared (CommandDenial::Protectedstill carries the class, read through aClassifycall). So:with_sandboxed_shell(..), set the same way aswith_scheduled_actions(bundle.rs,turn_exec/drive.rs) from the run'ssandbox_mode == Sandboxed.ShellTooluses the same check at Execute whensandbox_mode_for_tool(context)isSandboxed.Fail closed: a
Sandboxedrun always plans (should_plan_command), but the plan can still resolve to the host executor, for example when the operator turned the sandbox off. In that caserun_in_policyrefuses the command with the floor's original message (unjailed_floor_refusal), right after the backend is resolved. The native (non-plan) path also refuses a waived command. Commands outside the jail, scheduled shell jobs and every other tool keep the floor unchanged.3.
[runtime.local_jail]grants never reached the sandboxed shellSymptom:
extra_read_write,extra_read_only,toolchain_homesandallow_procreached the jail only with security off, or for the MCP sandbox. An operator could not give the sandboxed agent shell a readable code checkout or a writable scratch folder.Change:
ShellTool::run_sandboxednow applieslocal_grants::with_resolved_grantsto a native-jail (Local) policy before planning (shell_run::with_jail_grants). Containers and boxes keep their own mounts. If the grants cannot be resolved, the policy is left as it was.What still decides: TinyBox drops grants on TinySecurity's floor while resolving them. The spawn plan then admits each remaining grant through
PathScope::validate_grant(refused if it overlapsworkspace_dir, internal state, a reservation or a protected subtree) and checks it against the grant ceiling.credential_denialskeeps the core's secrets file, auth profiles, flow HTTP credentials andconfig.toml(credentials::credential_files), plus the native credential roots, on the jail's deny list, and refuses a plan whose workspace or writable grant sits inside one.What stays closed and why
spawn_plan::host_credential_denials). A grant that overlapsworkspace_diris refused by the plan.file_read,file_writeand the other file tools are untouched. They keep TinySecurity's path policy and the internal-state reservations.Tests
The new tests sit beside each module's existing tests:
middleware_failure_policy_class_tests.rs:refused_shell_commands_are_budgeted_per_commandthe_same_refused_shell_command_retried_still_stops_the_turnrefused_shell_commands_with_nothing_running_still_stop_the_turna_second_policy_block_on_another_tool_still_stops_the_turna_policy_block_allows_one_alternative_but_a_user_denial_does_notis updatedsecurity/policy/jailed_commands_tests.rs:host/security_gate_jailed_shell_tests.rs: the gate allows when sandboxed, refuses when not, and keeps the read-only refusal.shell_tests_runtime_and_sandbox_tests.rs: the Execute-stage check (jailed vs not, read-only kept) and the whole tool still refusing with no sandbox mode.shell_run_tests.rs:configured_local_jail_grants_reach_a_jailed_shell: extra grants arrive, a floor grant is dropped, a container keeps its own mountsonly_a_host_run_of_a_waived_command_is_refusedThe item-1 tests failed against the unchanged code (4 failed, the negative control passed) and pass after the fix. The item-2 and item-3 tests target new APIs, so against the old code they fail to compile rather than fail an assertion.
Commands run:
cargo test -p openhuman --lib -- agent::tinyagents security::policy tools::implementations::system::shell sandbox::local_grants: 652 passed, 12 failed.The 12 failures are environmental on the box I ran this on, and none involves the logic changed here:
[REDACTED](first_error_line_is_scrubbed…,tool_output…,terminal_inference…,loop_guard…,a_refused_integration…,a_refusal_later_in_the_batch…, anda_blocked_shell_command_lets_the_model_try_a_narrower_one, which fails only on itscontains("Unbounded system scan")check of the redacted error line);modules::security::policy::tests::concurrent_tenants_each_unlock_their_config_secretsfails because the security module is unavailable;shell_run::tests::a_sandboxed_command_yields_and_is_followed_to_its_endtimed out after 1s.I did not confirm these failures against base.
Other checks:
cargo clippy -p openhuman -- -D warnings: clean.cargo clippy --all-targetsreports pre-existing errors in other test files only.cargo fmtandnode scripts/ci/check-openhuman-rust-layout.mjsboth pass.Not done
unjailed_floor_refusal, applied inrun_in_policyright after the backend is resolved.shell_processand the exec adapters (tools/impl/system/exec_adapters.rs) still apply the floor unconditionally.vendor/. Waiving a single refusal inside the module, or returning the class with a floor refusal, would be cleaner as a TinySecurity contract change.JailEnforcement::Declared(partial, best effort). The waiver treats it as jailed, like Linux.Summary by CodeRabbit
New Features
Documentation