Skip to content

feat(sdk): add iam workload identity option and Secret.iamToken helper#1606

Open
mishushakov wants to merge 7 commits into
mainfrom
iam-sdk-feature
Open

feat(sdk): add iam workload identity option and Secret.iamToken helper#1606
mishushakov wants to merge 7 commits into
mainfrom
iam-sdk-feature

Conversation

@mishushakov

@mishushakov mishushakov commented Jul 24, 2026

Copy link
Copy Markdown
Member

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.create gains an iam option whose non-empty tokens map enables workload identity, and a new Secret class (exported from both main packages) provides iamToken / iam_token to define the token values, per the SDK design. The design doc's filePath field is deliberately omitted until it lands in the OpenAPI spec, and plain { audience, tokenType } objects are accepted alongside Secret.iamToken results. 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 missing audience/tokenType (token_type in Python) with InvalidArgumentError / InvalidArgumentException. Covered by request-body tests (msw in JS, NewSandbox payload 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

import { Sandbox, Secret } from 'e2b'

const sandbox = await Sandbox.create({
  iam: {
    tokens: {
      aws: Secret.iamToken({ audience: 'sts.amazonaws.com', tokenType: 'JWT-SVID' }),
    },
  },
})
from e2b import Sandbox, Secret

sandbox = Sandbox.create(
    iam={
        "tokens": {
            "aws": Secret.iam_token(audience="sts.amazonaws.com", token_type="JWT-SVID"),
        },
    },
)

🤖 Generated with Claude Code

mishushakov and others added 2 commits July 24, 2026 18:17
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>
@cla-bot cla-bot Bot added the cla-signed label Jul 24, 2026
@changeset-bot

changeset-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d472461

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
e2b Minor
@e2b/python-sdk Minor

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

@cursor

cursor Bot commented Jul 24, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches workload identity on sandbox create (security-sensitive), but changes are SDK request shaping and validation against an existing API with good test coverage.

Overview
Adds sandbox workload identity to the JS and Python SDKs (sync and async): Sandbox.create accepts an optional iam config with a named tokens map (audience + tokenType / token_type). A non-empty map is sent on create; empty or missing config is omitted from the request body.

Introduces exported Secret with iamToken / iam_token helpers; plain token objects work too. buildIamBody / build_iam_config validate required fields, strip extra keys (e.g. undeclared filePath), and reject malformed entries with clear client errors.

Covered by MSW tests (JS) and NewSandbox payload tests (Python); changeset bumps e2b and @e2b/python-sdk as minor.

Reviewed by Cursor Bugbot for commit d472461. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from 8a79081. Download artifacts from this workflow run.

JS SDK (e2b@2.36.1-iam-sdk-feature.0):

npm install ./e2b-2.36.1-iam-sdk-feature.0.tgz

CLI (@e2b/cli@2.15.2-iam-sdk-feature.0):

npm install ./e2b-cli-2.15.2-iam-sdk-feature.0.tgz

Python SDK (e2b==2.35.0+iam.sdk.feature):

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>
Comment thread packages/python-sdk/e2b/sandbox_async/sandbox_api.py
Comment thread packages/python-sdk/tests/sync/sandbox_sync/test_create.py
mishushakov and others added 2 commits July 24, 2026 18:35
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>
@mishushakov mishushakov changed the title feat(sdk): add iam workload identity option and Secret.idToken helper feat(sdk): add iam workload identity option and Secret.iamToken helper Jul 24, 2026
mishushakov and others added 2 commits July 24, 2026 18:49
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>
@linear-code

linear-code Bot commented Jul 24, 2026

Copy link
Copy Markdown

SDK-245

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant