Skip to main content
Workload identity lets code running in a sandbox prove who it is with short-lived identity tokens instead of long-lived credentials. Rather than baking cloud API keys into a template or passing them as environment variables, you define named workload tokens when creating the sandbox. Each token is scoped to an audience, the external service that will verify it, such as AWS STS. That service can exchange the token for its own temporary credentials.
Workload identity is currently in private beta. If you’d like access, please reach out to us at support@e2b.dev.

Configure

Pass the iam option when creating a sandbox. A non-empty tokens map enables workload identity for the sandbox. Each entry maps a token name you choose to a token definition, which you can create with the Secret helper.
You can also pass plain token definitions instead of using the Secret helper: { audience, tokenType } objects in JavaScript, {"audience": ..., "token_type": ...} dicts in Python.

Inject tokens into egress requests

Registered tokens can be injected into the sandbox’s outbound requests through per-host request transforms. Pass a callback as a network rule’s transform. It receives the registered tokens as iam.tokens.<name>:
iam.tokens.<name> is not the token value. It’s a placeholder string (${e2b.identity.tokens.<name>}) that goes on the wire as-is. The egress proxy replaces it with a freshly minted token each time it forwards a matching request, so the token value never reaches your code or the sandbox. Referencing a token name that isn’t registered in iam.tokens fails at sandbox creation with InvalidArgumentError (JavaScript) / InvalidArgumentException (Python), listing the names that are registered. You can check whether a name is registered without failing by using 'aws' in iam.tokens in JavaScript or "aws" in ctx.iam.tokens in Python.

Federate with external services

External systems can verify workload identity tokens with E2B’s OpenID Connect discovery document. The document identifies the issuer and the jwks_uri where E2B publishes its public signing keys. Verify tokens with ES256 and require the expected iss, aud, exp, and nbf claims. Also verify that the sub claim belongs to your project (it starts with spiffe://id.e2b.dev/<project-id>/), so tokens minted for other projects are rejected. Each token identifies one sandbox execution with a SPIFFE subject in this format:

Configure AWS IAM

AWS can exchange an E2B workload identity token with the sts.amazonaws.com audience for temporary role credentials.
1

Create an OIDC identity provider

In the AWS IAM console, open Identity providers, choose Add provider, and select OpenID Connect. Use these values:
  • Provider URL: https://id.e2b.dev
  • Audience: sts.amazonaws.com
You only need to create this provider once per AWS account. See the AWS OIDC provider documentation for other setup methods.
2

Create a role for E2B workloads

Create an IAM role with a custom trust policy. Replace <AWS_ACCOUNT_ID> and <E2B_PROJECT_ID> with your values:
The sub condition limits access to sandbox executions from one E2B project. You can find the project ID in the token’s project_id claim and as the first path segment after spiffe://id.e2b.dev/ in sub.Attach a permissions policy that grants only the AWS actions and resources these workloads need.
3

Exchange the token

After your external system receives the E2B workload identity token, it can exchange the token without long-lived AWS credentials:
The response contains temporary AWS credentials for the role. See the AssumeRoleWithWebIdentity API documentation for SDK examples and response details.
AWS credentials have their own lifetime. They remain valid after the E2B workload identity token expires or the sandbox ends. Configure the shortest role session duration that fits your workload.

Token definitions

Each token definition has two fields: Token names (the keys of the tokens map) are yours to choose. Creating a sandbox without the iam option, or with an empty tokens map, leaves workload identity disabled.

Limits

A sandbox can define up to 5 workload tokens. Exceeding the limit fails at sandbox creation with a 400 error.