Skip to content

feat(sandbox): sandbox cron scripts and command deliveries under [sandbox.consumers] cron (#748) - #874

Merged
ajianaz merged 2 commits into
developfrom
feat/748-sandbox-cron
Nov 16, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/748-sandbox-cron

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Third slice of #748: cron script jobs and command: deliveries can run in the command bubblewrap profile through a new consumer key [sandbox.consumers] cron = off (default) | optional | required (user config only).

Why

tole cron run / tick and tole serve --cron run owner-saved scripts and delivery commands unattended and unsandboxed; tole doctor said "cron scripts and deliveries are not sandboxed yet". Owner decision: same command profile as every other consumer, new key cron, and because cron is unattended optional has no unsandboxed fallback (Consumer::always_unattended, like verify and turnend): if the sandbox is unavailable or the plan is refused, the job refuses visibly; a launcher failure is a refusal, never a pass.

Changes

  • tole-core sandbox::command: Consumer::Cron (always unattended), Consumers.cron, new command_in_dir(consumer, workdir, program, args) (the existing command_prepared with the launcher report, workspace given by the caller), doctor lines (the "not sandboxed yet" line is replaced; cron is listed with the others and an ERROR is raised for optional/required without a backend).
  • tole-cli cron/launch.rs (new): the ONE launcher. tick::run_script and deliver::run_command both call launch::prepare and nothing else in src/cron builds a Command (a test asserts it). It reuses protect_plan/recheck_plan, the launcher status (bwrap --json-status-fd), rlimits, the cron secret scrub and the user config that cron run/tick already load (security: tole cron run and tole cron tick run agents and scripts without the owner's user config applied #863).
  • Config: cron key parsed, shown by config check, user layer only; main.rs refuses to start cron run/tick with cron on when the sessions directory cannot be protected (security: a sessions directory inside the workspace but outside .tole is writable by a sandboxed command #866), like verify and the stop gates.
  • Cron specifics:
    • workspace = the job's workdir (the process cwd when it has none; unknown cwd refuses). A workdir that is gone, holds $HOME or the data dir, or has a layout the plan refuses is a refusal. A workdir below a repository root binds that directory only (the parent .git is not in the sandbox).
    • deliveries follow the profile's grants and are not widened: with network = "none" a webhook/SMTP delivery fails (set network = "host", shared by all consumers); $HOME and paths outside the workdir are not visible. Documented in docs/sandbox-design.md §9.5.
    • stdout capture (1 MiB cap), the command's own exit code (from the launcher report; 125/126/127 stay the script's verdict), the delivery stdin and TOLE_CRON_* variables, the 300 s / 60 s timeouts and cancel are unchanged. A timeout is an error run, not a refusal.
    • a refusal settles the run error (never ok) with usage.sandbox_refused = true, the reason in usage.error and in the run log (so cron runs, GET /cron/runs and delivery targets show it); a refused or failed delivery is a failed record with the reason or the command's own exit code and stderr. usage.sandboxed says whether the run was wrapped.
    • MAILTO (fix(cron): tole cron run and tick apply the owner's user config (#863) #868): nothing new is written to stderr per tick (a refusal goes to the ledger and run log; optional has no fallback warning), asserted in the tests.
    • cron argv stays a bare program name (check_destructive_argv already refuses path-qualified programs at save and at run time), so the runs_paths exception of the stop gates is not extended to cron.
  • Docs: docs/sandbox-design.md (§9.3 text, new §9.5, §15), docs/threat-model.md, docs/epics.md, CHANGELOG.md. The README status line has no sandbox-slice text, so it is not stale.
  • ci.yml: the Sandbox (bubblewrap) job's tole-cli step runs --test cron_sandbox and now expects 3 passing targets (was 2).

Impact check (grep, not cora; the output is noisy on Rust so every caller was verified by grep):

  • Consumer::ALL / Consumer::name / Consumers::mode: sandbox/report.rs (doctor listing), command.rs doctor_lines_for, launch_command. always_unattended: launch_command, doctor_lines_for, report.rs. Consumers { .. } literals: command_sandbox*.rs, stopgate_sandbox.rs, command_sandbox_none.rs (updated with cron: Mode::Off), report_tests.rs, command_tests.rs (use ..Default), tole-cli/src/config/mod.rs.
  • SandboxConsumersConfig / settings(): config/mod.rs (render, provenance, consumers()), main.rs (set_consumers).
  • tick::run_script, ScriptOutput: only tick.rs. deliver::run_command: only deliver.rs.
  • Tests to rerun: command_sandbox, command_sandbox_none, command_sandbox_sessions, command_sandbox_sessions_refused, stopgate_sandbox, sandbox_no_flag, sandbox_profile_flag (tole-core), sandbox_consumers, verify_sandbox, sessions_default_dir_e2e, cron_cli, cron_delivery, cron_control, cron_trust, cron_user_config_e2e, cron_sandbox (tole-cli), the config:: and sandbox::command unit tests.

Testing

  • New crates/tole-cli/tests/cron_sandbox.rs (real binary, scrubbed env, 14 tests): off unchanged (default and explicit); required/optional without bwrap refuse visibly, script never runs, stderr empty; delivery refused and recorded; sandboxed script writes the workdir but not .git/.tole and cannot read the masked user config dir; own exit codes (3, 127) are not refusals; workdir below a repo root; gone workdir or one that holds the data dir; refused layout (uninitialized submodule); failing and unspawnable launcher (fake bwrap) are refusals; sandboxed delivery gets stdin and env and its failure is recorded; timeout kills a sandboxed script; no Command::new outside the one launcher.
  • Fail-first: with launch::prepare neutered by hand to a plain Command, 9 of the 13 behaviour tests fail (the 4 that still pass are the off control, the two exit-code tests and the timeout, which are meant to be backend-independent); restored before the commit.
  • Unit tests in sandbox/command_tests.rs (consumer list, always unattended with no fallback, profile identical to run_command, refused workdirs, doctor) and config/mod.rs; sandbox_consumers.rs doctor/config-check tests updated.
  • CI: cron_sandbox is added to the Sandbox (bubblewrap) job (honours TOLE_REQUIRE_BWRAP=1, count 2 to 3); no new tole-core target, the new core tests are unit tests in an existing module.
  • Local: cargo fmt --all; cargo clippy --workspace --all-targets --all-features -- -D warnings; clippy --no-default-features and --no-default-features --features shell-tools for tole-core/tole-cli; cargo check -p tole-core --no-default-features --tests; cargo test in the default workspace, -p tole-cli --no-default-features, -p tole-cli --no-default-features --features shell-tools and -p tole-core --no-default-features, all with TOLE_REQUIRE_BWRAP=1 --no-fail-fast: no failures.
  • cora is not installed in this environment, so scripts/review-local.sh and cora review --staged were not run; the diff was self-reviewed adversarially instead (launcher failure vs command exit, timeout classification, no-workdir and failing cwd, Off mode byte-for-byte, env scrub order, bypass paths by grep). The CI Cora Review job is the gate.
  • Attribution check over origin/develop..HEAD: nothing printed.

…dbox.consumers] cron (#748)

Third slice of #748. `[sandbox.consumers] cron` = off | optional | required
runs a cron script job and a `command:` delivery in the same `command`
profile as the other consumers, with the job's workdir as the workspace.
A cron job is unattended, so optional counts as required and there is no
unsandboxed fallback: a missing backend, a refused workdir or layout and a
failing launcher refuse the run or delivery visibly, never pass.

One launcher (cron/launch.rs) builds every process cron starts.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

…the fallback warning per consumer (#748)

A writable bind of a workdir that holds TOLE_CRON_DIR (or is inside it) let a
sandboxed script edit its own job ledger and run log. launch::prepare now
refuses it for scripts and deliveries and fails closed when the cron dir
cannot be resolved. warn_once keeps one bit per consumer so the new Cron
consumer cannot index out of bounds. CHANGELOG and docs state both.
@ajianaz
ajianaz merged commit 9507a4c into develop Nov 16, 2026
19 checks passed
@ajianaz
ajianaz deleted the feat/748-sandbox-cron 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