Skip to content

feat(sandbox): adopter levers to reach inside the Claude-family sandbox (closes #766) - #768

Merged
max-sixty merged 4 commits into
mainfrom
feat/sandbox-setup-lever
Jul 12, 2026
Merged

max-sixty merged 4 commits into
mainfrom
feat/sandbox-setup-lever

Conversation

@tend-agent

Copy link
Copy Markdown
Collaborator

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)

sandbox_path:            # dirs prepended to the sandbox PATH; leading ~ = sandbox home
  - ~/.cargo/bin
sandbox_env:            # NAME: VALUE added to the agent launch env (reserved keys rejected)
  RUST_BACKTRACE: "1"
sandbox_setup:          # commands run as the sandbox user, workspace cwd, after toolchain+plugins
  - rustup component add clippy

The motivating cargo-off-PATH case (#766) becomes sandbox_path: ["~/.cargo/bin"].

How it flows

  • config (config.py) — parses + validates. sandbox_env rejects 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) under codex, whose agent runs on the runner and already sees setup:.
  • generator (macros.yaml.j2) — threads the values into the Claude-family agent step as block-scalar action inputs. Not emitted for codex.
  • actions — claude + claude-interactive get matching sandbox_path/sandbox_env/sandbox_setup inputs (input-parity hook enforced). proxy/setup-sandbox.sh prepends sandbox_path (expanding a leading ~) to the PATH= line and appends validated sandbox_env lines to the agent env file. A new shared/steps/sandbox-setup.sh runs sandbox_setup as the sandbox user after toolchain + plugins install, before the run.

Security

The reserved-env guard lives in both config (fails at init) and setup-sandbox.sh (defends against a hand-edited workflow). Values are baked into the committed workflow at generation time, same trust model as setup: — a fork PR editing config can't inject; only a maintainer/nightly regen on the default branch bakes new values. sandbox_setup runs 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 runs codex exec directly on the runner (no proxy sandbox), so its setup: already reaches the agent — the keys warn and no-op there.

Tests

  • config-validation tests (reserved-key rejection, invalid env name, non-list types, scalar coercion, codex warning)
  • rendering tests (rendered for claude, absent by default, not rendered for codex)
  • a rendered-shape regtest locking the block-scalar output
  • all 268 generator tests pass; pre-commit (shellcheck, ruff, input-parity, ref-sync) green

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 tend-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread generator/src/tend/config.py Resolved
Comment thread shared/steps/sandbox-setup.sh Resolved
@max-sixty

Copy link
Copy Markdown
Owner

@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.
@tend-agent

Copy link
Copy Markdown
Collaborator Author

Pushed 3ac8f0d addressing all three review points:

  • Non-scalar sandbox_env values — now rejected at init with a clear "must be a scalar" error instead of str()-ing a list/dict into a Python repr in the agent env. Added a test.
  • sandbox-setup.sh — set -euo pipefail (was -eo), so a missing SANDBOX/AGENT_ENV_FILE export fails loudly, matching setup-sandbox.sh.
  • Reserved-key drift — added a sandbox-env-reserved-parity pre-commit hook that fails the commit if RESERVED_SANDBOX_ENV (config.py) and the case guard (setup-sandbox.sh) diverge, replacing comment-only sync for the security-relevant list. Went with the mechanical parity check rather than deriving from AGENT_ENV_FILE, since only one of the two auth-scheme vars is present in the file at runtime — deriving would stop guarding the inactive one.

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 tend-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_env boolean values render Python-cased. bool is an int subclass, so DEBUG: true falls into the int/float branch and str(True) writes DEBUG=True into the agent env, not the shell-conventional true/1. The coercion comment names true as an intended input and the error message lists boolean as accepted, so this is a real inconsistency. Inline suggestion below (it also rejects an embedded newline — see next point).
  • A newline in a sandbox_env value (or sandbox_path dir) produces a broken workflow. Both render at column 12 with no indent() filter (unlike sandbox_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-init rule. The sandbox_env fix is folded into the inline suggestion; sandbox_path needs the same one-line guard in its own validator.
  • sandbox_setup commands are fed on stdin. Piping the script to bash -s makes 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 to bash -c, which keeps stdin free and still needs no temp file.
  • The shell reserved re-check accepts a line with no =. A hand-edited sandbox_env: line like FOO (no =) yields name=FOO, which isn't reserved, so it's appended verbatim; env then 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=VALUE line before the case closes that path.
  • The codex inert-warning keys on the global harness. With harness: codex globally plus a per-workflow harness: claude override, the levers are active on that workflow (the macro renders per effective harness) yet load() 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_FILE is reserved"; the hook only compares RESERVED_SANDBOX_ENV against the shell case. 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.

Comment thread generator/src/tend/config.py Outdated
Comment on lines +356 to +364
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)"
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread shared/steps/sandbox-setup.sh Outdated
Comment on lines +23 to +29
# 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@tend-agent

Copy link
Copy Markdown
Collaborator Author

Pushed f38abd3 addressing all six points from the re-review:

  • Boolean values — bool is handled before the int/float branch, emitting shell-conventional true/false.
  • Newline in sandbox_env / sandbox_path — both reject a newline at init (must be a single line), so a value can't silently terminate the rendered block scalar.
  • sandbox_setup on stdin — now bash -c "$TEND_SANDBOX_SETUP" instead of piping on stdin, so a command that reads stdin can't swallow the remaining lines.
  • Non-NAME=VALUE line in the shell re-check — setup-sandbox.sh rejects a line with no = before the reserved case, closing the exec-the-token path for a hand-edited workflow.
  • Codex inert-warning — moved after the workflow parse and gated on the effective harness set, so a top-level codex with a per-workflow claude override (where the levers do apply) no longer warns.
  • Parity hook — also asserts every key written to AGENT_ENV_FILE (heredoc + both ANTHROPIC_DUMMY scheme keys) is in the reserved set, so a future routing/cred var added to the env file without reserving it fails the commit.

273 generator tests (4 new), ruff, shellcheck, and the parity hook all green locally.

@max-sixty
max-sixty merged commit 5e6d9fa into main Jul 12, 2026
7 of 9 checks passed
@max-sixty
max-sixty deleted the feat/sandbox-setup-lever branch July 12, 2026 08:55
@max-sixty max-sixty mentioned this pull request Jul 16, 2026
2 of 3 tasks
max-sixty added a commit that referenced this pull request Jul 16, 2026
## 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_
max-sixty pushed a commit to max-sixty/worktrunk that referenced this pull request Jul 17, 2026
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]>
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