Repository navigation
Keep research provider keys out of Claude Code and OpenCode sandboxes - #64
Merged
Merged
Conversation
Non-sealed Claude Code and OpenCode research sessions passed the host provider key into bwrap, where the agent's shell could read it from its environment and from /proc/$PPID/environ. Hold the key in a host loopback relay instead and give the sandbox only the relay URL and a disposable capability. - researchCredentialRelay: credential-custody protocol over the native relay (permissive admission, native usage accounting unchanged), Claude messages/count_tokens routes, OpenCode provider rewrite for the anthropic, openai and openai-compatible SDKs. - formalizationRelay: per-route upstream endpoints, forwarded anthropic-version/anthropic-beta headers, bounded redacted provider error bodies, configurable request cap (32 MiB for research). - Fail closed for Claude OAuth-only and unsupported OpenCode providers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Non-sealed Claude Code and OpenCode research sessions passed the host provider key into bwrap. A loopback repro with Claude Code 2.1.332 showed the agent's Bash tool reading
ANTHROPIC_API_KEY, and/proc/$PPID/environof the claude process contained it too. Sandbox network is inherited, so the key could leave the host.Fix
The key now stays in a host loopback relay. The sandbox gets only the relay URL and a disposable capability, the same pattern sealed roles and the Codex responses relay use.
src/runtime/researchCredentialRelay.ts(new)ANTHROPIC_API_KEY/ANTHROPIC_BASE_URLbecome the capability and relay URL. Routes:/v1/messagesand/v1/messages/count_tokens, each with?beta=true.ANTHROPIC_AUTH_TOKENuses Bearer upstream.baseURL/apiKeyare rewritten to the relay;headersare resolved on the host. Supports@ai-sdk/anthropic,@ai-sdk/openaiand@ai-sdk/openai-compatible.math_claude_oauth_credential_relay_unsupported) and other OpenCode SDKs (math_opencode_provider_relay_unsupported).src/runtime/formalizationRelay.ts: per-route upstream endpoints, forwardedanthropic-version/anthropic-beta, bounded redacted JSON provider errors (keeps 401/429/context-overflow classification), configurable request cap (32 MiB for research).native-turn-totals) and sealed paths are unchanged.Tests
npx tsc --noEmitpasses.out/directory missing in the worktree; codexSessionFileWatch failed once under full-suite load and passes alone.Not covered
Codex's own
/procenviron, the genericcliharnessinheritEnvironmentkeys, a Claude login stored in a profile, and literal keys written into a profile'sopencode.json.Not deployed. Running runtimes were not touched.
🤖 Generated with Claude Code