Skip to content

feat(sandbox): sandbox the mission --verify command (#748) - #845

Merged
ajianaz merged 6 commits into
developfrom
feat/748-sandbox-verify
Nov 15, 2026
Merged

ajianaz merged 6 commits into
developfrom
feat/748-sandbox-verify

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Second slice of #748, part 1 of 2 (this PR: the mission --verify command; the on_turnend stop gates follow in a stacked PR, opened after this one merges). [sandbox.consumers] verify = "off" | "optional" | "required" (user config only, default off) runs the sh -c <verify> of tole mission in the existing command profile, including the #849 protection of the whole .git directory, nested gitdirs and .tole. Refs #748 (stays open for the stop gates, cron scripts and deliveries).

Why

The verify command runs code the agent just wrote (cargo test runs build scripts and tests) with no approval (#676). Opt-in first, as decided on 2026-11-14; making verify sandboxed by default is a later phase (plan in docs/sandbox-design.md §9.4, not done here).

Changes

  • tole-core sandbox/command.rs: Consumer::Verify, Consumers.verify, Consumer::ALL, command_in_cwd (same as command_for, workspace = the process's working directory, which is where verify ran before; only looked up when the sandbox is on), preflight (the refusal a launch would give, without running anything). launch_command passes unattended || consumer.always_unattended(): a mission is unattended, so optional counts as required for verify whatever the process flag says. Launcher status via bwrap --json-status-fd: command_exit_code is Some only when the command itself ran and ended. Doctor lines list the consumer; an optional verify without a sandbox is an ERROR (a mission cannot fall back), a toolchain-under-$HOME warning, and the stop gates are still reported "not sandboxed yet". Commands still read consumers(), never session_policy().
  • tole-cli mission.rs: run_verify goes through command_in_cwd and returns Verify::{Passed, Failed, Refused}. What "verify refused" does to a mission: a refusal ends the mission with status verify_refused and a non-zero exit. A start-up check (preflight) runs before the first turn, so no model turn is spent on a mission that cannot be verified. Refusals: no working sandbox (required or optional), no workspace, a workspace layout the command profile refuses (uninitialized or nested submodule, linked worktree inside the workspace, a .git link chain it cannot protect; the reason is printed), a launcher that fails to start (spawn error, or a non-zero exit with no command exit code from bwrap). MISSION_COMPLETE is not honoured, verify_failures stays 0, the session stays resumable, no skill outcome is recorded. It is never a pass and never an unsandboxed run: a mission is unattended, so optional has no fallback (run_command falls back with a human attached; verify cannot). A command that runs and fails (or times out) is unchanged: output back to the model, 3 strikes verify_failed.
  • Off: the spawned command is the old one (sh -c, same scrub for consumer verify, same timeout and output tail). On: same exit status, output capture, timeout, cwd, ENV-1 scrub (applied to the bwrap process).
  • config/mod.rs: verify key (validated, config check, user layer only). main.rs: --verify help mentions verify_refused.
  • Docs: docs/sandbox-design.md §9.2/9.3/9.4 (call site, semantics, refusal incl. profile-refused layouts, residual: toolchains in ~/.cargo are not visible), epics, threat model, CHANGELOG. CI: Sandbox (bubblewrap) job also runs the tole-cli target verify_sandbox.
  • develop merged (includes security: the command sandbox profile protects .git/hooks and .git/config by leaf mounts only; renaming .git aside bypasses them #849/fix(sandbox): bind the whole .git read-only in the command profile (#849) #851, fix(security): refuse --no-config under an agent session and on serve, acp and mcp #858); conflicts were only both-sides additions (CI step, test files, the threat-model row, which keeps the security: the command sandbox profile protects .git/hooks and .git/config by leaf mounts only; renaming .git aside bypasses them #849 wording plus the verify sentences).

Callers and impact (cora is absent here; grep, every one checked):

  • Consumer / Consumers / command_for / launch_command: run_command.rs and jobs.rs (unchanged behaviour, command_for is a wrapper of command_prepared), sandbox/report.rs (doctor_grant_lines loops Consumer::ALL), config/mod.rs, main.rs (set_consumers), doctor.rs (command::doctor_lines); struct-literal users in tests use ..Default.
  • run_verify: only mission.rs. classify_mission (skill/outcome.rs): verify_refused falls under the existing Skip arm.
  • Tests rerun: command_tests.rs, command_sandbox{,_none}.rs, sandbox_no_flag.rs, sandbox_profile_flag.rs, sandbox_consumers.rs, mission_e2e.rs, verify_sandbox.rs, config unit tests, layering.
  • Windows/macOS: no new platform code; detect() says "no sandbox on this platform" and tole doctor and the refusal repeat it.

Testing

  • Argv builder tests per flag for verify (command_tests.rs): same argv as run_command, protected paths read-only, the string stays one argv element after --, optional is required, refusal text names sandbox.consumers.verify, doctor lines, the launcher report parser.
  • Policy without bubblewrap (command_sandbox_none.rs, verify_sandbox.rs, real binary + mock provider): verify off (default and explicit) unchanged; required and optional without bwrap refuse: status: verify_refused, non-zero exit, the command never ran, turns: 0, verify failures: 0, never complete.
  • With bubblewrap (command_sandbox.rs, verify_sandbox.rs; skip with a SKIPPED: line when bwrap is absent, CI's Sandbox (bubblewrap) job runs them with TOLE_REQUIRE_BWRAP=1): a sandboxed verify writes the workspace but cannot write .git, .tole, sees no $HOME or data dir, keeps its exit status and output; a failing sandboxed verify is verify_failed after 3 strikes; a layout the profile refuses (uninitialized submodule, linked worktree) in both required and optional is verify_refused with the profile's reason, turns: 0, the command never ran; fake-bwrap tests: a launcher failure and an unspawnable launcher are refusals, not verify failures.
  • Fail without the change (reverted by hand, restored): run_verify back to a plain sh -c => the refusal and .git write tests fail; always_unattended made false => the unit, command_sandbox_none and doctor tests fail; Refused mapped to Failed => both refusal e2e tests fail.
  • Gates on the final head: cargo fmt --all --check; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo clippy -p tole-core -p tole-cli -p tole-tui --no-default-features --all-targets -- -D warnings; cargo test of tole-core and tole-cli (default) and of tole-core, tole-cli, tole-tui with --no-default-features, all with TOLE_REQUIRE_BWRAP=1: green, no SKIPPED.
  • scripts/review-local.sh: cora is not installed here (exit 1, not a pass). Self-review as adversarial reviewer of git diff origin/develop...HEAD: a refusal can never reach the pass branch (the Verify enum has no default arm and Refused breaks before any continuation); the workspace is canonicalised and refused for $HOME/ancestors/data dir by check_grant; the sh -c string is one argv element after --; the scrub is on the bwrap process; command_in_cwd never calls session_policy() so --sandbox/--no-sandbox cannot reach verify; an unknown cwd refuses. Residual documented: --workspace is not the sandbox workspace (the process cwd is, as before), toolchains outside system dirs are not visible, and the security: the command sandbox profile protects .git/hooks and .git/config by leaf mounts only; renaming .git aside bypasses them #849 residuals of the command profile apply to verify too.

@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

…fore the first turn, say what a sandboxed verify cannot see (#748)
@ajianaz
ajianaz merged commit 329ff8c into develop Nov 15, 2026
23 checks passed
ajianaz added a commit that referenced this pull request Nov 15, 2026
…review items (#748)

Adds [sandbox.consumers] turnend = "off" | "optional" | "required" (user config only, default off). Stop gates run in the existing command profile with the whole-.git protection. A refusal (no working sandbox, a workspace layout the profile refuses, an unspawnable launcher, or a non-zero exit with no command exit code from bwrap) is a deny with a reason, never a pass. Consumer::always_unattended now covers verify and turnend, so optional has no unsandboxed fallback for a stop gate. A gate timeout keeps the old non-blocking contract (#110), documented as a residual.

Also folds in the three low items from the #845 review: the fd 3 doc wording, the doctor warning strings, and real-bwrap tests that exit codes 125/126/127 and forged fd 3 lines do not change the classification.

Refs #748 (stays open for cron scripts and deliveries).
@ajianaz
ajianaz deleted the feat/748-sandbox-verify branch November 20, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants