Skip to content

fix(#8635): take hook settings from the runner after .env on all runtimes - #8637

Merged
waynesun09 merged 2 commits into
mainfrom
agent/8635-hook-settings-runner-env
Oct 20, 2026
Merged

waynesun09 merged 2 commits into
mainfrom
agent/8635-hook-settings-runner-env

Conversation

@fullsend-ai-coder

Copy link
Copy Markdown
Contributor

Summary

Claude Code and pi launches now take the sandbox hook settings from the runner after the .env load, as codex already did. The codex code moves into a runtime-neutral helper, internal/runtime/sandbox_hooks_env.go, and all three runtimes use it. The launch also unsets any of the five names the runner has no value for, so a value that only .env carries never reaches the hooks.

Changes

  • New sandbox_hooks_env.go
    • bootstrapHookEnv records the SandboxHookConfig-derived values and the harness pair (FULLSEND_CANARY_TOKEN, FULLSEND_TOOL_ALLOWLIST). The pair is read back from .env before the first iteration.
    • hookEnvExports renders unset <names without a value> && export K='v' ....
    • configHookEnv and readHarnessHookEnv are the former codexSecurityEnv and codexReadHarnessSecurityEnv, renamed.
  • Codex: uses the helper. It now unsets the names it has no value for; before, an empty harness value was exported as ''. Goldens regenerated; the only change is one unset line.
  • Claude Code: installClaudeHooks records the values in claudeHookDigests.SecurityEnv. buildRunCommandWithDigests re-asserts them after the second hooks guard, before the gateway post-env.
  • pi: Bootstrap records the values in a runner-side piHookEnvs map, next to piManifestHashes. buildPiRunCommand re-asserts them right before the launch, after the declared-extension env and the gateway env. childEnv copies the launch env ({...base}) and only deletes provider credentials, so the hook adapter and sub-agents inherit the values. A new JS test locks that in.
  • Docs: docs/runtimes/{claude,codex,pi}.md say that hook settings come from the harness configuration at Bootstrap and that .env cannot change them. docs/contributing/runtime-implementation.md no longer describes this as codex-only.

Testing

  • TestHookEnv_LaunchesTakeTheRunnerValues: for each runtime, the test builds the real launch command and takes its .env load plus the hook-env statements between that load and the CLI start. It runs them under /bin/sh with a .env that changes every managed name. The hooks must see the Bootstrap values, and no value for a name the runner did not set. A control subtest confirms that the .env alone does reach the hooks, so the check is not vacuous.
  • Mutation check, done by hand: with the re-export dropped from each of the three builders, or with the unset removed from hookEnvExports, every runtime subtest fails.
  • Bootstrap recording and read-failure tests for Claude and pi, plus unit tests for hookEnvExports. Existing stubs answer the new Bootstrap read.
  • go test -race ./internal/runtime/ passes. Patch coverage on changed Go lines is about 92%.
  • make lint: pre-commit could not fetch its hook repos in the sandbox (TLS failure). The applicable hooks were run directly and pass: whitespace, EOF, gofmt, go vet, gitleaks (scan-secrets), broken symlinks, docs links and lychee.
  • Tests added/updated for new or modified logic

Caveats

  • If pi's launch has no Bootstrap entry (Bootstrap ran in another process), it emits nothing and keeps today's behaviour. This matches its manifest guard. Claude Code and codex still fail closed through their guards.
  • fullsend-agent.test.mjs "a timed-out child gets SIGTERM..." fails in the agent sandbox on main too. It is unrelated to this change.

Checklist

  • PR title follows Conventional Commits (correct type, ! for breaking changes)
  • Commits are signed off (DCO): not applicable, this is an autonomous agent commit
  • I wrote this contribution myself and can explain all changes in it

🤖 Generated with Claude Code


Closes #8635

Post-script verification

  • Branch is not main/master (agent/8635-hook-settings-runner-env)
  • Secret scan passed (gitleaks — d93007f9d8c36709a6eacf42bb2d43a9d93f7042..HEAD)
  • PR body secret scan passed (gitleaks — no-git)

@waynesun09

Copy link
Copy Markdown
Member

/fs-fix-stop

@github-actions github-actions Bot added the fullsend-no-fix Skip bot-triggered fix agent runs label Oct 20, 2026
@github-actions

Copy link
Copy Markdown

Fix agent disabled for this PR. Remove the fullsend-no-fix label or use /fs-fix to re-engage.

@fullsend-ai-review

fullsend-ai-review Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 9:50 PM UTC · Completed 10:02 PM UTC

Commit: fc6568b · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $3.15

@fullsend-ai-review fullsend-ai-review Bot added the risk/moderate PR risk: moderate label Oct 20, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

<!-- fullsend:risk-assessment -->
Risk Assessment: moderate (2/5)

Details

Large change size across runtime files with high churn is mitigated by zero protected path edits, strong test ratio, bot authorship, and close alignment with linked issue #8635.

Previous run

<!-- fullsend:risk-assessment -->
Risk Assessment: moderate (2/5)

Details

Moderate risk: large change size across runtime files with high churn is balanced by zero protected path edits, strong test ratio, bot authorship, and close alignment with linked issue #8635.

@fullsend-ai-review

fullsend-ai-review Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review

Findings

Low

  • [naming-convention] internal/runtime/codex_run_test.go:771 — TestCodexSecurityEnv_PinsWhatTheRunnerKnows keeps the runtime-specific CodexSecurityEnv prefix, but this PR renamed the function it tests from codexSecurityEnv to the runtime-neutral configHookEnv (now in sandbox_hooks_env.go). The sibling test TestCodexSecurityEnv_BeatsTheAgentsEnvFile at line 803 has the same stale prefix.
    Remediation: Rename the test to TestConfigHookEnv_PinsWhatTheRunnerKnows (or move it to sandbox_hooks_env_test.go) to match the renamed helper.
Previous run

<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJjb21tZW50IiwiZmluZGluZ3MiOlt7InNldmVyaXR5IjoibWVkaXVtIiwiY2F0ZWdvcnkiOiJmYWlsLW9wZW4iLCJmaWxlIjoiaW50ZXJuYWwvcnVudGltZS9waV9ydW4uZ28iLCJpZCI6ImZfZDEyZTgzMGFhZGE2ODVmNSIsImxpbmUiOjYyMywiYWN0aW9uYWJsZSI6ZmFsc2V9LHsic2V2ZXJpdHkiOiJsb3ciLCJjYXRlZ29yeSI6InBhdHRlcm4taW5jb25zaXN0ZW5jeSIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL3BpX2Jvb3RzdHJhcC5nbyIsImlkIjoiZl8zYjdiMzgxMmY5OWY5NDA0IiwibGluZSI6NDI1LCJhY3Rpb25hYmxlIjpmYWxzZX0seyJzZXZlcml0eSI6ImxvdyIsImNhdGVnb3J5IjoiY29kZS1vcmdhbml6YXRpb24iLCJmaWxlIjoiaW50ZXJuYWwvcnVudGltZS9jb2RleF9ib290c3RyYXBfdGVzdC5nbyIsImlkIjoiZl80ODhkZWU5OTY5Y2Q0NDBiIiwibGluZSI6Njc5LCJhY3Rpb25hYmxlIjpmYWxzZX0seyJzZXZlcml0eSI6ImxvdyIsImNhdGVnb3J5IjoibmFtaW5nLWNvbnZlbnRpb24iLCJmaWxlIjoiaW50ZXJuYWwvcnVudGltZS9jb2RleF9ydW5fdGVzdC5nbyIsImlkIjoiZl81ZWRhNzYyZWFlNDc4ZmRiIiwibGluZSI6NzcxLCJhY3Rpb25hYmxlIjpmYWxzZX0seyJzZXZlcml0eSI6ImxvdyIsImNhdGVnb3J5IjoiZG9jLXN0eWxlIiwiZmlsZSI6ImRvY3MvY29udHJpYnV0aW5nL3J1bnRpbWUtaW1wbGVtZW50YXRpb24ubWQiLCJpZCI6ImZfMzA2Nzg2MTMwMTcyODAzZCIsImxpbmUiOjEzOTUsImFjdGlvbmFibGUiOmZhbHNlfV19 -->

Review

Findings

Medium

  • [fail-open] internal/runtime/pi_run.go:623 — When hooks are enabled and piHookEnv has no runner-side entry, buildPiRunCommand emits no hookEnvExports and still launches pi, so the five hook settings come from the agent-writable .env. PiRuntime.Run does not reject the missing entry, while Claude Code and codex fail closed. The gap only opens when Bootstrap and Run run in different processes: the one production caller (internal/cli/run.go) runs both in one process, the agent cannot remove the entry, pi's manifest guard skips itself in the same case, and the base branch had no re-assertion for pi at all. It is a defence-in-depth inconsistency, not a regression.
    Remediation: Consider failing closed like Claude Code and codex: when HooksSettingsPath is set and piHookEnv(sandbox) has no entry, have Run return an error, and change TestBuildPiRunCommand_HookEnvNeedsBootstrapEntry to expect the launch to be refused.

Low

  • [pattern-inconsistency] internal/runtime/pi_bootstrap.go:425 — piHookEnvs has no per-sandbox forget helper; tests use resetPiHookEnvs, which clears every entry, whereas sibling state (forgetClaudeHookDigests, forgetRunnerHeldDigests) is cleared per sandbox.
    Remediation: Optionally add a per-sandbox forget helper and use it in place of resetPiHookEnvs.
  • [code-organization] internal/runtime/codex_bootstrap_test.go:679 — TestCodexReadHarnessSecurityEnv and TestCodexReadHarnessSecurityEnvCmd test the runtime-neutral readHarnessHookEnv/readHarnessHookEnvCmd but kept the old names and file.
    Remediation: Move them to sandbox_hooks_env_test.go and rename them TestReadHarnessHookEnv and TestReadHarnessHookEnvCmd.
  • [naming-convention] internal/runtime/codex_run_test.go:771 — TestCodexSecurityEnv_PinsWhatTheRunnerKnows tests configHookEnv but keeps the old TestCodexSecurityEnv_ prefix naming the deleted identifier.
    Remediation: Rename it to TestConfigHookEnv_PinsWhatTheRunnerKnows.
  • [doc-style] docs/contributing/runtime-implementation.md:1395 — The edited line is about 133 characters, over the ~80-column prose wrapping rule in docs/contributing/documentation.md.
    Remediation: Rewrap the paragraph at word boundaries.

Labels: PR changes runtime launch/hook environment handling in the agent runner

fullsend-ai-review[bot]

This comment was marked as outdated.

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-review fullsend-ai-review Bot added requires-manual-review Review requires human judgment component/runner Agent runner behavior and lifecycle labels Oct 20, 2026
fullsend-ai-coder Bot and others added 2 commits October 20, 2026 18:46
…imes

The sandbox hook scripts read TIRITH_FAIL_ON, TIRITH_REQUIRED,
FULLSEND_EGRESS_ALLOWLIST, FULLSEND_CANARY_TOKEN and
FULLSEND_TOOL_ALLOWLIST from the environment, and the workspace .env
that carries them is agent-writable. Codex recorded them at Bootstrap
and re-exported them after the .env load. The Claude Code and pi
launches did not, so iteration 1 could change what iteration 2's
hooks saw.

Move the codex mechanism into sandbox_hooks_env.go:
- bootstrapHookEnv records the SandboxHookConfig values plus the
  harness pair, read back from .env before the first iteration.
- hookEnvExports exports each name the runner has a value for and
  unsets the rest, so a value only .env carries never reaches the
  hooks (codex included; it used to export only names with values).

Claude Code keeps the values in claudeHookDigests and pi in a
runner-side map next to piManifestHashes; both re-assert them after
.env. pi's childEnv copies the launch env, so the hook adapter and
sub-agents inherit them. A pi launch with no Bootstrap entry emits
nothing, as for its manifest guard.

Tests run each runtime's .env handling under /bin/sh with a .env
that changes every name. Dropping the re-export or the unset fails
them. Codex goldens regenerated; docs updated.

Note: pre-commit could not fetch its hook repos (TLS failure in the
sandbox). The hooks that apply to these files were run directly
(whitespace, EOF, gofmt, go vet, gitleaks via scan-secrets, broken
symlinks, docs links, lychee) and pass. One pi JS test (SIGTERM to
grandchildren) also fails on main in this sandbox; it is unrelated.

Closes #8635

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With sandbox hooks on, buildPiRunCommand re-asserts the hook settings
only when Bootstrap recorded them in this process; without a record the
launch left them to .env. Run now refuses to start pi in that case, as
Claude Code and codex refuse without their runner-held digests.

Also rewrap the edited contributor-docs paragraph.

Assisted-by: Claude (fix), Codex (review)
Signed-off-by: Wayne Sun <gsun@redhat.com>
@fullsend-ai-review

fullsend-ai-review Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🤖 Review · ❌ Terminated · Started 10:54 PM UTC · Ended 11:06 PM UTC

Commit: 52a2e54 · View workflow run →

@github-actions

Copy link
Copy Markdown

Site preview

Preview: https://d6afaef6-site.fullsend-ai.workers.dev

Commit: 52a2e5460ac4487a9f9969b2d008434570c32d9c

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.53488% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/runtime/sandbox_hooks_env.go 83.63% 6 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@fullsend-ai-review fullsend-ai-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note: The following review comments could not be posted on the diff (GitHub returned 422) and are included here instead:

  • internal/runtime/codex_run_test.go (file-level): Line 771 ·
    [low] naming-convention

TestCodexSecurityEnv_PinsWhatTheRunnerKnows keeps the runtime-specific CodexSecurityEnv prefix, but this PR renamed the function it tests from codexSecurityEnv to the runtime-neutral configHookEnv (now in sandbox_hooks_env.go). The sibling test TestCodexSecurityEnv_BeatsTheAgentsEnvFile at line 803 has the same stale prefix.

Suggested fix: Rename the test to TestConfigHookEnv_PinsWhatTheRunnerKnows (or move it to sandbox_hooks_env_test.go) to match the renamed helper.

@fullsend-ai-review fullsend-ai-review Bot added ready-for-merge All reviewers approved — ready to merge and removed requires-manual-review Review requires human judgment labels Oct 20, 2026
@fullsend-ai-review

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:54 PM UTC · Completed 11:05 PM UTC

Commit: 52a2e54 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.90

@waynesun09 waynesun09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Validated in the sandbox image as the sandbox user under dash: with a .env that changes or adds each hook setting, the hooks (ssrf_pretool.py, tool_allowlist_pretool.py) see the Bootstrap values and the names the runner did not set are unset. Go suite passes on Linux with dash as /bin/sh; JS suite passes.

@waynesun09
waynesun09 added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit 5bbf11a Oct 20, 2026
112 checks passed
@waynesun09
waynesun09 deleted the agent/8635-hook-settings-runner-env branch October 20, 2026 23:52
gklein pushed a commit to gklein/fullsend that referenced this pull request Oct 21, 2026
…ings document

Claude Code merges the --settings document fullsend generates with
$CLAUDE_CONFIG_DIR/settings.json and the repository's
.claude/settings.json and .claude/settings.local.json. --settings wins
only for the keys it sets, so an env block in a lower-priority file was
applied inside Claude Code after the launch re-exported the hook
settings (fullsend-ai#8637), and a disableAllHooks there could switch the hooks
off.

installClaudeHooks now records the hook settings (bootstrapHookEnv)
before it renders hooks.json, and claudeRunnerSettings adds to the
document, on every run:

- env: TIRITH_FAIL_ON, TIRITH_REQUIRED, FULLSEND_EGRESS_ALLOWLIST,
  FULLSEND_CANARY_TOKEN and FULLSEND_TOOL_ALLOWLIST with the values
  Bootstrap recorded, or "" (unset) where the runner has none. On
  gateway runs these are merged into the claudeGatewaySettings env
  block instead of replacing it.
- "disableAllHooks": false.

Both land in the hooks.json digest the launch guard checks and in the
inline document on gateway runs.

After .env the launch also unsets CLAUDE_CODE_SAFE_MODE,
CLAUDE_CODE_SIMPLE and CLAUDE_CODE_SHELL_PREFIX
(claudeSettingsEnvUnset), next to claudeLoaderEnvUnset.

Tests cover the env block (values and "") and disableAllHooks on the
non-gateway and both gateway routes, the merged gateway env, the
digest, and the launch under /bin/sh and dash with a .env exporting
the three variables, with a control run showing they reach claude
without the unset. Each test was mutation-checked by dropping the
change it covers.

Note: pre-commit could not fetch remote hook repos in the sandbox
(TLS failure). The local hooks (gofmt, go vet, lint-broken-symlinks,
lint-docs-links, lychee) were run directly and pass; whitespace and
EOF were checked by hand, and secrets were scanned with scan-secrets.

Closes fullsend-ai#8641

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jctanner added a commit to jctanner-fullsend-ai/fullsend that referenced this pull request Oct 29, 2026
Renumber the ADR 0150 -> 0152 (0146-0151 are claimed by open PRs
fullsend-ai#8679, fullsend-ai#8694, fullsend-ai#8698, fullsend-ai#8702; fullsend-ai#8702 was filed first for 0150).

Per waynesun09's reviews (first round 14:56, second round 18:29):

- restructure the Decision as rules 1-10 with the conformance table
  separated out (moved to docs/contributing/runtime-implementation.md
  so it can track the implementation as the code changes, linked from
  Consequences)
- add the Options section back per the ADR template (fail-open with
  warning, per-runtime resolvers, version-floor acceptance,
  hash-verification as primary mechanism — each rejected)
- add rules 9 (executables, not just directories) and 10 (scope:
  settings sources fullsend-ai#8637, hooks.json integrity fullsend-ai#8261, plugin trust
  ADR 0094)
- gaps against the rules are tracked in issues, not the ADR: fullsend-ai#8763
  (per-file trust for every executable a hook runs) and fullsend-ai#8764 (paths
  that let a tool call through without a hook verdict), both filed by
  the reviewer; rule 8's root-launch exception stays as a one-sentence
  stated limit
- fix the pre-fullsend-ai#8605 Codex wording: the PATH was restored for itself
  and its hook adapter's children
- fix the architecture.md sentence to state the decision for all
  runtimes, not Codex only
- factual corrections from the first round: the shared resolver is
  hookPreflightInterpreter; the boundary value is FULLSEND_TRUSTED_PATH;
  the pre-fullsend-ai#8605 gap was image-PATH agent-writable dirs; pi included
  (same treatment in fullsend-ai#8589, pinned python3 not Node)

Per the dual-model review round (GLM 5.3 + DeepSeek V4.1 Flash):
- breaking change names the runtimes (pi has no version preflight)
- forge scope before Consequences, full forge list

Signed-off-by: James Tanner <jtanner@redhat.com>

This branch was successfully deployed

1 active and 1 inactive deployments
site-preview — 52a2e546 Deployed Oct 20, 2026 by github-actions[bot]
dev — 52a2e546 Deployed Oct 20, 2026 by waynesun09 via playback #17419
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/runner Agent runner behavior and lifecycle fullsend-no-fix Skip bot-triggered fix agent runs ready-for-merge All reviewers approved — ready to merge ready-for-review Triggers review agent dispatch risk/moderate PR risk: moderate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook settings: take them from the runner after .env on Claude Code and pi, as codex does

1 participant