Workload identity is currently in private beta.
If you’d like access, please reach out to us at support@e2b.dev.
Configure
Pass theiam 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.
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’stransform. 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 thejwks_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 thests.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
2
Create a role for E2B workloads
Create an IAM role with a custom trust policy. Replace The
<AWS_ACCOUNT_ID> and <E2B_PROJECT_ID> with your values: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.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 a400 error.