feat(sdk): add iam workload identity option and Secret.iamToken helper#1606
feat(sdk): add iam workload identity option and Secret.iamToken helper#1606mishushakov wants to merge 7 commits into
Conversation
Adds the `iam` creation option from the infra spec (SandboxIam /
SandboxIamTokens / SandboxIamToken, already present in the pinned spec
and generated clients): a non-empty `tokens` map of name ->
{ audience, tokenType } enables workload identity for the sandbox.
- JS: `SandboxIamOpts` / `SandboxIamToken` types, `iam` on `SandboxOpts`,
passed through in the POST /sandboxes body.
- Python (sync + async): `SandboxIamOpts` / `SandboxIamToken` TypedDicts,
`iam` kwarg on `Sandbox.create` / `AsyncSandbox.create`, converted to
the generated client models via shared `build_iam_config`.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds the `Secret` class from the SDK design, exported from both main
packages, with a static `idToken` (JS) / `id_token` (Python) method that
returns a workload-token definition passable as a value in `iam.tokens`
on `Sandbox.create`. Plain `{ audience, tokenType }` objects remain
accepted too.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: d472461 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
PR SummaryMedium Risk Overview Introduces exported Covered by MSW tests (JS) and Reviewed by Cursor Bugbot for commit d472461. Bugbot is set up for automated code reviews on this repo. Configure here. |
Package ArtifactsBuilt from 8a79081. Download artifacts from this workflow run. JS SDK ( npm install ./e2b-2.36.1-iam-sdk-feature.0.tgzCLI ( npm install ./e2b-cli-2.15.2-iam-sdk-feature.0.tgzPython SDK ( pip install ./e2b-2.35.0+iam.sdk.feature-py3-none-any.whl |
Aligns the token factory with the rest of the feature's name family (`iam.tokens` option, `SandboxIamToken` schema): `Secret.iamToken` / `Secret.iam_token`, and `SecretIdTokenOpts` -> `SecretIamTokenOpts`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The spec deliberately leaves tokenType an open string, and the backend accepts only "JWT-SVID" in this version (iamTokenTypeJWTSVID in infra's sandbox_create.go). SandboxIamTokenType gives autocomplete for the known value without closing the set, so newer or self-hosted backends can accept types this SDK version doesn't know about. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Addresses review feedback on #1606: - build_iam_config returns None for a config with no tokens, so iam={} / iam={"tokens": {}} omit the field like the sibling network config instead of sending "iam": {} (ClientSandboxIam is an attrs class and always truthy, so `or UNSET` alone never omitted it); the JS body builder now applies the same rule for parity. - Mirror the three iam payload tests into the async test suite, matching the auto_resume test convention. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Moves the inline empty-iam omission out of the create body literal into a buildIamBody helper, mirroring buildNetworkBody and Python's build_iam_config. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- buildIamBody rebuilds the request body from known fields instead of passing the caller's object by reference, skips undefined token values so they don't defeat the omit-empty guard, and rejects tokens missing string audience/tokenType with InvalidArgumentError - build_iam_config raises InvalidArgumentException naming the snake_case token_type key instead of a bare KeyError on malformed token dicts - Secret.iamToken takes SandboxIamToken directly, dropping the duplicated SecretIamTokenOpts interface - iam msw suite fails loudly on unhandled requests (error, not bypass) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Implements the sandbox workload identity (IAM) feature from the infra spec (
SandboxIam/SandboxIamTokens/SandboxIamToken, already present in the pinned spec and generated clients) across the JS SDK and the sync and async Python SDKs.Sandbox.creategains aniamoption whose non-emptytokensmap enables workload identity, and a newSecretclass (exported from both main packages) providesiamToken/iam_tokento define the token values, per the SDK design. The design doc'sfilePathfield is deliberately omitted until it lands in the OpenAPI spec, and plain{ audience, tokenType }objects are accepted alongsideSecret.iamTokenresults. The SDK builds the request body from only the known token fields (stray properties never reach the wire, undefined-valued map entries count as empty) and rejects tokens missingaudience/tokenType(token_typein Python) withInvalidArgumentError/InvalidArgumentException. Covered by request-body tests (msw in JS,NewSandboxpayload tests in Python) since the backend feature is team-gated; all three surfaces were also smoke-tested end-to-end against production, where the payload is parsed and answered with the expected team-gating error.Fixes SDK-245.
Usage
🤖 Generated with Claude Code