Skip to content

[sandbox] Let an embedding CLI supply auth headers for each request - #406

Closed
Melkeydev wants to merge 1 commit into
mainfrom
melkey/sandbox-auth-headers
Closed

Melkeydev wants to merge 1 commit into
mainfrom
melkey/sandbox-auth-headers

Conversation

@Melkeydev

Copy link
Copy Markdown
Contributor

Lets a CLI that embeds sandbox (like vercel sandbox) supply the auth headers for each API request, so a sender-constrained token such as a DPoP-bound one (RFC 9449) can be used. Without the new option nothing changes.

Why

A DPoP-bound access token is rejected when it's sent as Authorization: Bearer. It has to be sent as Authorization: DPoP <token> with a new DPoP proof for every request, signed for that method and URL. Today every sandbox API request sends Bearer, so an embedding CLI with such a token can't use sandbox commands.

Approach

Every SDK request from the CLI already goes through the CLI's fetchWithUserAgent, which the SDK's retry wrapper calls once per attempt. So that's the one place to add the headers:

  • createApp({ getAuthHeaders }): an optional (method, url) => Promise<headers>, set for the run and cleared after.
  • fetchWithUserAgent calls it for each attempt and replaces the Authorization header with what it returns. Only requests that already carry the token are touched.
  • inferScope from @vercel/sandbox/dist/auth takes an optional fetch, and the CLI passes fetchWithUserAgent, so scope inference (/v2/user, /v2/teams, the default project) uses it too.
  • Snapshot.get now also goes through fetchWithUserAgent, like the other clients.

No SDK request API changes: the SDK keeps sending Bearer, and the CLI swaps the header.

Validation

  • New client.test.ts cases: the headers replace Bearer, a retried request (500, then 200) gets new headers for each attempt, and without getAuthHeaders the request still sends Bearer. The retry case fails without the change.
  • New infer-scope.test.ts case: the given fetch reaches every API request.
  • sandbox: tsc --noEmit clean, 230 tests pass. @vercel/sandbox: tsc --noEmit clean, auth tests pass (28).

@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sandbox Ready Ready Preview, v0 Oct 26, 2026 2:53am UTC
sandbox-cli Ready Ready Preview, v0 Oct 26, 2026 2:53am UTC
sandbox-sdk-ai-example Ready Ready Preview, v0 Oct 26, 2026 2:53am UTC
workflow-code-runner Ready Ready Preview, v0 Oct 26, 2026 2:53am UTC

@roboeve

roboeve Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Closing for now.

@roboeve roboeve Bot closed this Oct 26, 2026

This branch was successfully deployed

4 active deployments
Preview – sandbox — 02ef32c1 Deployed Oct 26, 2026 by vercel[bot]
Preview – sandbox-sdk-ai-example — 02ef32c1 Deployed Oct 26, 2026 by vercel[bot]
Preview – workflow-code-runner — 02ef32c1 Deployed Oct 26, 2026 by vercel[bot]
Preview – sandbox-cli — 02ef32c1 Deployed Oct 26, 2026 by vercel[bot]
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.

1 participant