Repository navigation
feat(sandbox): adopter levers to reach inside the Claude-family sandbox (closes #766) - #768
Conversation
Add sandbox_path / sandbox_env / sandbox_setup config keys so an adopter can extend PATH, add env vars, and run commands INSIDE the proxy sandbox before the agent launches. Runner-side `setup:` runs as the runner user around the composite action and never reaches the sandbox's fixed env allowlist; these three keys do. - config: parse + validate the keys; reject reserved env names (proxy routing, CA trust, dummy credentials, PATH) so an adopter can't redirect the agent off the injecting proxy; warn (inert) under the codex harness, whose agent runs on the runner and already sees `setup:`. - generator: thread the values into the Claude-family agent step as block-scalar action inputs (not emitted for codex). - claude + claude-interactive actions: new sandbox_path/sandbox_env/ sandbox_setup inputs (kept in parity). setup-sandbox.sh prepends sandbox_path (leading ~ -> sandbox home) to PATH and appends validated sandbox_env to the agent env file; a new shared/steps/sandbox-setup.sh runs sandbox_setup as the sandbox user after toolchain+plugins install. - docs + tests: example config section, config-validation and rendering tests, and a rendered-shape regtest. The cargo-off-PATH case becomes `sandbox_path: ["~/.cargo/bin"]`. Closes #766
tend-agent
left a comment
There was a problem hiding this comment.
Self-review. The design is sound and well-tested; two small correctness/consistency fixes inline, plus one maintainability note.
Reserved-key list is duplicated without a parity guard. RESERVED_SANDBOX_ENV in config.py and the case list in proxy/setup-sandbox.sh are kept aligned only by comments. The repo already treats this exact hazard mechanically for the two Claude actions (claude-action-input-parity in .pre-commit-config.yaml), because comment-based sync rots. Here the drift is security-relevant: add a var to the AGENT_ENV_FILE heredoc and forget the case list, and an adopter's sandbox_env can override that var past the boundary the re-check exists to defend. Worth either a small parity check, or deriving the shell guard from the names already written to AGENT_ENV_FILE (reject any sandbox_env name that already appears in the file) so there's a single source of truth. Not blocking — flagging for a follow-up.
|
@tend-agent please fix based on review? |
…tup.sh, add reserved-key parity guard Addresses PR #768 review: - config.py: sandbox_env now rejects non-scalar values (list/dict) at init instead of str()-ing them into a Python repr in the agent env. - sandbox-setup.sh: set -euo pipefail (was -eo) so a missing SANDBOX / AGENT_ENV_FILE export fails loudly, matching setup-sandbox.sh. - pre-commit: new sandbox-env-reserved-parity hook fails the commit if RESERVED_SANDBOX_ENV (config.py) and the case guard (setup-sandbox.sh) drift; the shell re-check is the security boundary.
|
Pushed
269 generator tests, ruff, shellcheck, and the new parity hook all green. |
The prior commit staged 14 generator/**/__pycache__/*.pyc build artifacts. Untrack them and add a .gitignore rule so they can't return.
tend-agent
left a comment
There was a problem hiding this comment.
Re-reviewed after 3ac8f0d — the three prior points (non-scalar rejection, set -euo pipefail, the reserved-key parity hook) are all addressed and CI is green. A fresh pass over the incremental turned up a few refinements, none blocking:
sandbox_envboolean values render Python-cased.boolis anintsubclass, soDEBUG: truefalls into theint/floatbranch andstr(True)writesDEBUG=Trueinto the agent env, not the shell-conventionaltrue/1. The coercion comment namestrueas an intended input and the error message listsbooleanas accepted, so this is a real inconsistency. Inline suggestion below (it also rejects an embedded newline — see next point).- A newline in a
sandbox_envvalue (orsandbox_pathdir) produces a broken workflow. Both render at column 12 with noindent()filter (unlikesandbox_setup), so a value containing a newline drops an un-indented continuation line that terminates the|block scalar. The generator writes it unvalidated, so it fails only when GitHub Actions later refuses to load the workflow — the opposite of the repo's fail-at-initrule. Thesandbox_envfix is folded into the inline suggestion;sandbox_pathneeds the same one-line guard in its own validator. sandbox_setupcommands are fed on stdin. Piping the script tobash -smakes the script text the commands' own stdin, so a setup command that reads stdin (an installer prompt,read, etc.) silently swallows the remaining commands and the step still exits 0. Inline suggestion below switches tobash -c, which keeps stdin free and still needs no temp file.- The shell reserved re-check accepts a line with no
=. A hand-editedsandbox_env:line likeFOO(no=) yieldsname=FOO, which isn't reserved, so it's appended verbatim;envthen treats the assignment-less token as the command to exec and the agent never launches. Since the re-check exists specifically to defend hand-edited workflows, rejecting a non-NAME=VALUEline before thecasecloses that path. - The codex inert-warning keys on the global harness. With
harness: codexglobally plus a per-workflowharness: claudeoverride, the levers are active on that workflow (the macro renders per effective harness) yetload()still prints "inert under codex" — and the inverse (global claude, per-workflow codex) warns not at all. Minor: gating on whether any effective harness is Claude-family would match the render logic. - The parity hook guards config↔shell but not the heredoc. The invariant that matters is "every key written to
AGENT_ENV_FILEis reserved"; the hook only comparesRESERVED_SANDBOX_ENVagainst the shellcase. All 20 heredoc keys are covered today, so no live hole — but a future credential/routing var added to the heredoc without updating the reserved set would pass the hook. Optional hardening: also assert the heredoc keys are a subset of the reserved set.
| if isinstance(value, str): | ||
| sandbox_env[name] = value | ||
| elif isinstance(value, (int, float)): | ||
| sandbox_env[name] = str(value) | ||
| else: | ||
| raise click.ClickException( | ||
| f"sandbox_env value for '{name}' must be a scalar " | ||
| "(string, number, or boolean)" | ||
| ) |
There was a problem hiding this comment.
| if isinstance(value, str): | |
| sandbox_env[name] = value | |
| elif isinstance(value, (int, float)): | |
| sandbox_env[name] = str(value) | |
| else: | |
| raise click.ClickException( | |
| f"sandbox_env value for '{name}' must be a scalar " | |
| "(string, number, or boolean)" | |
| ) | |
| if isinstance(value, bool): | |
| coerced = "true" if value else "false" | |
| elif isinstance(value, str): | |
| coerced = value | |
| elif isinstance(value, (int, float)): | |
| coerced = str(value) | |
| else: | |
| raise click.ClickException( | |
| f"sandbox_env value for '{name}' must be a scalar " | |
| "(string, number, or boolean)" | |
| ) | |
| if "\n" in coerced: | |
| raise click.ClickException( | |
| f"sandbox_env value for '{name}' must be a single line" | |
| ) | |
| sandbox_env[name] = coerced |
bool is an int subclass, so handle it before the int/float branch and emit lowercase; the trailing check keeps a newline-bearing value from silently producing a broken block scalar in the rendered workflow.
There was a problem hiding this comment.
Applied in f38abd3 — bool is now handled before the int/float branch (DEBUG: true → DEBUG=true), and both sandbox_env values and sandbox_path dirs are rejected at init if they contain a newline. Added test_sandbox_env_coerces_boolean_lowercase, test_sandbox_env_newline_value_rejected, and test_sandbox_path_newline_rejected.
| # Run as the sandbox user with the agent's launch env. The script text is piped | ||
| # on stdin (read by `bash -s`) rather than via a temp file, so no sandbox-side | ||
| # read permission on a runner-owned path is needed. `set -e` inside so a failing | ||
| # setup command fails the step loudly rather than silently proceeding to the run. | ||
| mapfile -t AGENT_ENV <"$AGENT_ENV_FILE" | ||
| printf '%s\n' "$TEND_SANDBOX_SETUP" \ | ||
| | sudo -u "$SANDBOX" env "${AGENT_ENV[@]}" bash -eo pipefail -s |
There was a problem hiding this comment.
| # Run as the sandbox user with the agent's launch env. The script text is piped | |
| # on stdin (read by `bash -s`) rather than via a temp file, so no sandbox-side | |
| # read permission on a runner-owned path is needed. `set -e` inside so a failing | |
| # setup command fails the step loudly rather than silently proceeding to the run. | |
| mapfile -t AGENT_ENV <"$AGENT_ENV_FILE" | |
| printf '%s\n' "$TEND_SANDBOX_SETUP" \ | |
| | sudo -u "$SANDBOX" env "${AGENT_ENV[@]}" bash -eo pipefail -s | |
| # Run as the sandbox user with the agent's launch env. The commands go through | |
| # `bash -c`'s argument: no temp file (so no sandbox-side read permission on a | |
| # runner-owned path), and not stdin (so a setup command that reads stdin can't | |
| # swallow the remaining lines). `-e` inside so a failing setup command fails the | |
| # step loudly rather than silently proceeding to the run. | |
| mapfile -t AGENT_ENV <"$AGENT_ENV_FILE" | |
| sudo -u "$SANDBOX" env "${AGENT_ENV[@]}" bash -eo pipefail -c "$TEND_SANDBOX_SETUP" |
There was a problem hiding this comment.
Applied in f38abd3 — switched to bash -eo pipefail -c "$TEND_SANDBOX_SETUP", so the commands no longer own stdin and a setup command that reads stdin can't swallow the rest.
Addresses the second self-review pass on #768: - sandbox_env booleans coerce to lowercase true/false (bool is an int subclass; str(True) was writing Python-cased DEBUG=True) - reject a newline in any sandbox_env value or sandbox_path dir at init — it would drop an un-indented continuation line and break the block scalar - run sandbox_setup via bash -c (not stdin -s) so a command reading stdin can't swallow the rest and exit 0 - reject a non-NAME=VALUE sandbox_env line in setup-sandbox.sh before the reserved case (an =-less token would exec as a command) - gate the codex inert-warning on effective harness so a per-workflow claude override doesn't warn - parity hook also asserts AGENT_ENV_FILE heredoc keys are reserved
|
Pushed
273 generator tests (4 new), ruff, shellcheck, and the parity hook all green locally. |
## Summary Version bump + CHANGELOG for 0.1.11. See [CHANGELOG.md](https://github.com/max-sixty/tend/blob/release/CHANGELOG.md#0111) for the full notes. 13 commits since 0.1.10: - Adopter sandbox levers (`sandbox_path`/`sandbox_env`/`sandbox_setup`, #768) - Sandbox `PATH` derived from the runner's own `PATH` (#767) - Invited upstream contributions (#770) - `tend-mention` self-comment no-op skip (#751) - Actionable self-review handling (#762, #775) - `tend-outage` dedup self-heal (#744) - Dropped-cron-tick recovery in `list-recent-runs` (#753) - Drop self-authored attribution sign-offs (#773) - Docs fixes (#776, #771) - `claude_version` bump (#774) ## Test plan - [x] `wt test` (275 passed) - [x] `pre-commit run --all-files` (all hooks passed) - [ ] CI green on this PR > _This was written by Claude Code on behalf of Maximilian Roos_
Automated nightly regeneration of tend's workflow files, picking up the upstream release. **tend version:** 0.1.10 → 0.1.11 **Notable changes** (consumer-relevant): - Skip no-op `tend-mention` sessions triggered by the bot's own comments — a new pre-mention guard in the generated `tend-mention.yaml` short-circuits before the engagement heuristics (max-sixty/tend#751). - Respond to actionable bot self-reviews instead of exiting as a self-loop: a review the review workflow leaves on its own PR is the bot's reviewer role, so it gets actioned rather than silently skipped (max-sixty/tend#762). - Sandbox: adopter levers to reach inside the Claude-family sandbox, and derive the sandbox `PATH` from the runner's `PATH` (max-sixty/tend#768, max-sixty/tend#767). - `running-in-ci`: permit maintainer-invited upstream contributions, and prohibit self-authored attribution sign-offs (max-sixty/tend#770, max-sixty/tend#773). - Action reliability: self-heal duplicate `tend-outage` issues from concurrent leg failures, and recover dropped cron ticks in list-recent-runs via a previous-run anchor (max-sixty/tend#744, max-sixty/tend#753). Compare: max-sixty/tend@0.1.10...0.1.11 Co-authored-by: worktrunk-bot <[email protected]>
Implements Option 2 from #766 (@max-sixty: "let's do (2)") — the general lever for an adopter to reach inside the Claude-family sandbox before the agent launches. Runner-side
setup:runs as the runner user around the composite action and never reaches the sandbox's fixed env allowlist; these three keys do.Config surface (
.config/tend.yaml, top-level)The motivating cargo-off-PATH case (#766) becomes
sandbox_path: ["~/.cargo/bin"].How it flows
config.py) — parses + validates.sandbox_envrejects a reserved set (proxy routing, CA trust, dummy credentials,PATH) so an adopter can't redirect the agent off the injecting proxy or clobber the dummy secrets. Warns (inert) undercodex, whose agent runs on the runner and already seessetup:.macros.yaml.j2) — threads the values into the Claude-family agent step as block-scalar action inputs. Not emitted for codex.claude+claude-interactiveget matchingsandbox_path/sandbox_env/sandbox_setupinputs (input-parity hook enforced).proxy/setup-sandbox.shprependssandbox_path(expanding a leading~) to thePATH=line and appends validatedsandbox_envlines to the agent env file. A newshared/steps/sandbox-setup.shrunssandbox_setupas the sandbox user after toolchain + plugins install, before the run.Security
The reserved-env guard lives in both config (fails at
init) andsetup-sandbox.sh(defends against a hand-edited workflow). Values are baked into the committed workflow at generation time, same trust model assetup:— a fork PR editing config can't inject; only a maintainer/nightly regen on the default branch bakes new values.sandbox_setupruns at the same non-privileged sandbox UID the agent already runs as, so it's no privilege escalation.Scope note
sandbox_*is Claude-family only. Codex runscodex execdirectly on the runner (no proxy sandbox), so itssetup:already reaches the agent — the keys warn and no-op there.Tests