Skip to content

Commit 5c5fb7c

Browse files
committed
Merge origin/main into fix/issue-766
Resolve the setup-sandbox.sh PATH conflict by combining both levers: the adopter's explicit sandbox_path (TEND_SANDBOX_PATH) is prepended so it wins, then the runner-PATH auto-derivation pulls in the /etc/skel-seeded toolchains. Adopter dirs dedup against the auto-derived rewrites. Also regenerate the stale test_sandbox_levers snapshot, which was left mismatched against the mention template on main by #762.
2 parents 682ffe1 + 8c50fc5 commit 5c5fb7c

20 files changed

Lines changed: 1028 additions & 13 deletions

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Runtime artifact written by the harness composite action at CI time
22
# (claude/action.yaml, claude-interactive/action.yaml). Never commit it.
33
.claude/settings.local.json
4+
5+
# Python bytecode caches (generator/).
6+
__pycache__/
7+
*.py[cod]

‎.pre-commit-config.yaml‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,60 @@ repos:
170170
)
171171
sys.exit(1)
172172
pass_filenames: false
173+
174+
# The set of env names an adopter's `sandbox_env:` may NOT set lives in
175+
# two places: RESERVED_SANDBOX_ENV in generator/src/tend/config.py (fails
176+
# at `init`) and the `case "$name"` guard in proxy/setup-sandbox.sh
177+
# (re-checks a hand-edited workflow). The shell re-check is the actual
178+
# security boundary; if it drifts below the config set, an adopter's
179+
# sandbox_env can override a routing/credential var past it. Kept in sync
180+
# by comments alone this rots — this guard fails the commit if the two
181+
# sets diverge.
182+
- id: sandbox-env-reserved-parity
183+
name: reserved sandbox_env set stays in sync
184+
language: system
185+
files: ^(generator/src/tend/config\.py|proxy/setup-sandbox\.sh)$
186+
entry: python3
187+
args:
188+
- -c
189+
- |
190+
import re, sys
191+
192+
py = open("generator/src/tend/config.py").read()
193+
block = re.search(r"RESERVED_SANDBOX_ENV = \{(.*?)\}", py, re.S).group(1)
194+
config_set = set(re.findall(r'"([^"]+)"', block))
195+
196+
sh = open("proxy/setup-sandbox.sh").read()
197+
case = re.search(r'case "\$name" in\s*(.*?)\)', sh, re.S).group(1)
198+
case = case.replace("\\\n", "").replace("\n", "")
199+
shell_set = {n.strip() for n in case.split("|") if n.strip()}
200+
201+
# The invariant that matters: every key written to AGENT_ENV_FILE is
202+
# reserved, so an adopter's sandbox_env can't shadow it. Extract the
203+
# heredoc keys and the ${ANTHROPIC_DUMMY} scheme keys (either arm may
204+
# be written at runtime) and assert they're a subset of the reserved
205+
# set — so a future routing/cred var added to the heredoc without
206+
# updating the reserved set fails the commit.
207+
heredoc = re.search(r'cat >"\$AGENT_ENV_FILE" <<EOF\n(.*?)\nEOF', sh, re.S).group(1)
208+
heredoc_keys = set(re.findall(r'^([A-Za-z_][A-Za-z0-9_]*)=', heredoc, re.M))
209+
heredoc_keys |= set(re.findall(r'ANTHROPIC_DUMMY="([A-Za-z_][A-Za-z0-9_]*)=', sh))
210+
211+
problems = []
212+
for name in sorted(config_set - shell_set):
213+
problems.append(f"'{name}' is reserved in config.py but NOT guarded in setup-sandbox.sh")
214+
for name in sorted(shell_set - config_set):
215+
problems.append(f"'{name}' is guarded in setup-sandbox.sh but NOT reserved in config.py")
216+
for name in sorted(heredoc_keys - config_set):
217+
problems.append(f"'{name}' is written to AGENT_ENV_FILE but NOT reserved in config.py — an adopter's sandbox_env could shadow it")
218+
219+
for p in problems:
220+
print(p)
221+
if problems:
222+
print(
223+
"\nERROR: the reserved sandbox_env set drifted between "
224+
"config.py, setup-sandbox.sh, and the AGENT_ENV_FILE "
225+
"heredoc. The shell case is the security boundary; keep "
226+
"every env-file key reserved and the two sets aligned."
227+
)
228+
sys.exit(1)
229+
pass_filenames: false

‎claude-interactive/action.yaml‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ inputs:
5050
default: "true"
5151
description: Include the full Claude transcript in the workflow step summary.
5252
claude_version:
53-
default: "2.1.201"
53+
default: "2.1.207"
5454
description: >-
5555
Version of the `claude` binary to install via
5656
`https://claude.ai/install.sh`, pinned to a specific
@@ -67,6 +67,25 @@ inputs:
6767
description: >-
6868
Pinned `mitmproxy` version for the credential-injection proxy. Pinned
6969
so the uv download cache key is stable; bump to upgrade.
70+
sandbox_path:
71+
default: ""
72+
description: >-
73+
Newline-separated directories prepended to the sandbox agent's PATH,
74+
before the agent launches. A leading `~` expands to the sandbox home.
75+
Runner-side `setup:` steps can't reach the sandbox env; this can.
76+
sandbox_env:
77+
default: ""
78+
description: >-
79+
Newline-separated NAME=VALUE pairs added to the sandbox agent's launch
80+
environment. Reserved keys (proxy routing, CA trust, dummy credentials,
81+
PATH) are rejected — use `sandbox_path` to extend PATH.
82+
sandbox_setup:
83+
default: ""
84+
description: >-
85+
Shell commands run as the sandbox user after the toolchain and plugins
86+
install and before the agent runs, with the agent's launch env and the
87+
workspace as cwd. For on-disk setup (installing a tool, warming a cache);
88+
env-only tweaks don't persist — use sandbox_path/sandbox_env for those.
7089
7190
outputs:
7291
token_usage:
@@ -176,6 +195,10 @@ runs:
176195
ACTION_PATH: ${{ github.action_path }}/..
177196
MITMPROXY_VERSION: ${{ inputs.mitmproxy_version }}
178197
UV_CACHE_DIR: ${{ runner.temp }}/tend-mitmproxy-uv
198+
# Adopter sandbox levers: PATH prepends and env additions, baked into
199+
# the agent env file. sandbox_setup (commands) runs in a later step.
200+
TEND_SANDBOX_PATH: ${{ inputs.sandbox_path }}
201+
TEND_SANDBOX_ENV: ${{ inputs.sandbox_env }}
179202
run: bash "${{ github.action_path }}/../proxy/setup-sandbox.sh"
180203

181204
# Install the agent toolchain (uv + the claude binary) into the sandbox
@@ -237,6 +260,15 @@ runs:
237260
env:
238261
MARKETPLACE_ROOT: ${{ github.action_path }}/..
239262

263+
# Run the adopter's `sandbox_setup:` commands inside the sandbox, as the
264+
# sandbox user, after the toolchain + plugins are in place and before the
265+
# agent launches. No-op when the input is empty.
266+
- name: Run adopter sandbox setup
267+
shell: bash
268+
run: bash "${{ github.action_path }}/../shared/steps/sandbox-setup.sh"
269+
env:
270+
TEND_SANDBOX_SETUP: ${{ inputs.sandbox_setup }}
271+
240272
# The supervisor pattern, in three pieces:
241273
# 1. .claude/settings.local.json sets `permissions.defaultMode:
242274
# bypassPermissions`, plus Stop/StopFailure hooks. Stop writes a

‎claude/action.yaml‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ inputs:
5252
default: "true"
5353
description: Include the rendered Claude transcript in the workflow step summary.
5454
claude_version:
55-
default: "2.1.201"
55+
default: "2.1.207"
5656
description: >-
5757
Version of the `claude` binary to install via
5858
`https://claude.ai/install.sh`, pinned to a specific
@@ -69,6 +69,25 @@ inputs:
6969
description: >-
7070
Pinned `mitmproxy` version for the credential-injection proxy. Pinned
7171
so the uv download cache key is stable; bump to upgrade.
72+
sandbox_path:
73+
default: ""
74+
description: >-
75+
Newline-separated directories prepended to the sandbox agent's PATH,
76+
before the agent launches. A leading `~` expands to the sandbox home.
77+
Runner-side `setup:` steps can't reach the sandbox env; this can.
78+
sandbox_env:
79+
default: ""
80+
description: >-
81+
Newline-separated NAME=VALUE pairs added to the sandbox agent's launch
82+
environment. Reserved keys (proxy routing, CA trust, dummy credentials,
83+
PATH) are rejected — use `sandbox_path` to extend PATH.
84+
sandbox_setup:
85+
default: ""
86+
description: >-
87+
Shell commands run as the sandbox user after the toolchain and plugins
88+
install and before the agent runs, with the agent's launch env and the
89+
workspace as cwd. For on-disk setup (installing a tool, warming a cache);
90+
env-only tweaks don't persist — use sandbox_path/sandbox_env for those.
7291
7392
outputs:
7493
token_usage:
@@ -187,6 +206,10 @@ runs:
187206
ACTION_PATH: ${{ github.action_path }}/..
188207
MITMPROXY_VERSION: ${{ inputs.mitmproxy_version }}
189208
UV_CACHE_DIR: ${{ runner.temp }}/tend-mitmproxy-uv
209+
# Adopter sandbox levers: PATH prepends and env additions, baked into
210+
# the agent env file. sandbox_setup (commands) runs in a later step.
211+
TEND_SANDBOX_PATH: ${{ inputs.sandbox_path }}
212+
TEND_SANDBOX_ENV: ${{ inputs.sandbox_env }}
190213
run: bash "${{ github.action_path }}/../proxy/setup-sandbox.sh"
191214

192215
# Install the agent toolchain (uv + the claude binary) into the sandbox
@@ -206,6 +229,15 @@ runs:
206229
env:
207230
MARKETPLACE_ROOT: ${{ github.action_path }}/..
208231

232+
# Run the adopter's `sandbox_setup:` commands inside the sandbox, as the
233+
# sandbox user, after the toolchain + plugins are in place and before the
234+
# agent launches. No-op when the input is empty.
235+
- name: Run adopter sandbox setup
236+
shell: bash
237+
run: bash "${{ github.action_path }}/../shared/steps/sandbox-setup.sh"
238+
env:
239+
TEND_SANDBOX_SETUP: ${{ inputs.sandbox_setup }}
240+
209241
# Run the agent headless. `claude -p` (print mode) runs one turn to
210242
# completion and exits — no Ink UI, no TTY, no first-run onboarding — so
211243
# completion is detected from the process exit code plus the final

‎docs/tend.example.yaml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,39 @@ bot_name: my-project-bot
161161
# # env:
162162
# # RUSTFLAGS: -D warnings
163163

164+
# ## Sandbox setup (Claude-family harnesses)
165+
#
166+
# `setup:` above runs as the RUNNER user, around the composite action — it
167+
# does not reach the agent's environment. The `claude` and `claude-interactive`
168+
# harnesses run the agent as a separate, non-sudo sandbox user with a fixed
169+
# env allowlist, so runner-side PATH/env changes don't carry in. These three
170+
# keys reach INSIDE that sandbox, before the agent launches:
171+
#
172+
# - `sandbox_path`: directories prepended to the sandbox PATH. A leading `~`
173+
# expands to the sandbox home. This is the fix for a toolchain installed in
174+
# the sandbox home but off PATH (e.g. rustup's shims):
175+
#
176+
# sandbox_path:
177+
# - ~/.cargo/bin
178+
#
179+
# - `sandbox_env`: NAME: VALUE pairs added to the agent's launch env. Reserved
180+
# keys (proxy routing, CA trust, dummy credentials, PATH) are rejected — use
181+
# `sandbox_path` for PATH:
182+
#
183+
# sandbox_env:
184+
# RUST_BACKTRACE: "1"
185+
#
186+
# - `sandbox_setup`: shell commands run as the sandbox user after the toolchain
187+
# and plugins install and before the agent runs, with the workspace as cwd.
188+
# For on-disk effects (installing a tool, warming a cache); env-only tweaks
189+
# don't persist across the command's shell — use sandbox_path/sandbox_env:
190+
#
191+
# sandbox_setup:
192+
# - rustup component add clippy
193+
#
194+
# The codex harness runs the agent on the runner, so its `setup:` section
195+
# already reaches the agent env; these keys are inert (and warn) under codex.
196+
164197
# ## Workflows
165198
#
166199
# All workflows are enabled by default except ci-fix (requires

0 commit comments

Comments
 (0)