Llim.run

Authenticate E2B sandboxes with workload identity federation

E2B gives each sandbox a workload identity JWT but never shows it to code inside the sandbox. Its egress proxy adds the JWT to outbound requests you configure. You set up Limrun to trust E2B's tokens, then create sandboxes whose proxy hands the token to Limrun's token service, so no Limrun API key enters the sandbox.

Before you start

You need:

Create the provider

E2B signs tokens for all of its customers, so the provider condition must check that a token belongs to your project.

  1. Open console.limrun.com, go to Settings, then Workload identity federation, and click the + button next to Identity providers.

  2. In Issuer, choose E2B. The preset fills in the issuer https://id.e2b.dev and its signing keys at https://id.e2b.dev/.well-known/jwks.json.

  3. Keep Token audience as limrun. The sandbox requests its token with this audience.

  4. In Provider condition (CEL), replace PROJECT_ID with your project ID:

    assertion.sub.startsWith('spiffe://id.e2b.dev/PROJECT_ID/')
  5. Click Create provider. Limrun fetches E2B's signing keys before it saves the provider.

Create a binding

  1. In the provider's card, click the + button next to Bindings.
  2. Enter a name and a Claim condition (CEL). true admits every sandbox in your project. E2B's discovery document also lists sandbox_id, execution_id, and template_id claims. Decode a token from one of your sandboxes to see their values before you narrow the condition with them.
  3. Enter the permissions the sandboxes need, one per line, such as xcode:*:all.
  4. Click Create binding, expand Setup, and copy the binding ID.

Create a sandbox that sends its token to Limrun

When you create the sandbox, define a workload token with the audience limrun and a network rule that adds it to requests for sts.limrun.com in the X-Limrun-Subject-Token header:

import { Sandbox, Secret } from 'e2b';

const sandbox = await Sandbox.create({
  iam: {
    tokens: { limrun: Secret.iamToken({ audience: 'limrun', tokenType: 'JWT-SVID' }) },
  },
  network: {
    allowOut: ({ rules }) => [...rules.keys()],
    rules: {
      'sts.limrun.com': [
        { transform: ({ iam }) => ({ headers: { 'X-Limrun-Subject-Token': iam.tokens.limrun } }) },
      ],
    },
  },
});
from e2b import Sandbox, Secret

sandbox = Sandbox.create(
    iam={
        "tokens": {"limrun": Secret.iam_token(audience="limrun", token_type="JWT-SVID")},
    },
    network={
        "allow_out": lambda ctx: list(ctx.rules.keys()),
        "rules": {
            "sts.limrun.com": [
                {"transform": lambda ctx: {"headers": {"X-Limrun-Subject-Token": ctx.iam.tokens["limrun"]}}},
            ],
        },
    },
)

iam.tokens.limrun is a placeholder. E2B's proxy replaces it with a signed token on the way out, so the value never passes through code in the sandbox. A rule's host must also be allowed in allowOut. If the sandbox restricts outbound traffic, also allow the Limrun API and the hosts your instances use.

Run lim in the sandbox

Inside the sandbox, tell the CLI to rely on the injected token and point Node at the certificate authority E2B's proxy uses:

export LIMRUN_WORKLOAD_IDENTITY_TOKEN_INJECTED=true
export LIMRUN_WORKLOAD_IDENTITY_BINDING_ID=binding_REPLACE_WITH_BINDING_ID
export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt
lim whoami

lim whoami prints your organization and the binding's permissions. E2B's proxy decrypts traffic to sts.limrun.com with its own certificate authority, which E2B adds to /etc/ssl/certs/ca-certificates.crt. Node reads NODE_EXTRA_CA_CERTS only at startup, so set it before you start the CLI or your application. For the Python SDK, set SSL_CERT_FILE to the same file instead. The Go SDK uses the system bundle.

The same variables configure the SDKs, or pass workloadTokenInjected, workload_token_injected, or TokenInjected explicitly. Each lim command, and each SDK renewal, exchanges a token again, and E2B's proxy attaches a valid token each time.

Troubleshoot

ErrorCause
invalid_requestThe exchange reached Limrun without a token. Check that the rule's host is exactly sts.limrun.com and that allowOut includes it.
invalid_grantLimrun rejected the token or the binding. Check the binding ID, that the token's audience matches the provider's, and that the project ID in the provider condition is correct.
A certificate errorNode does not trust E2B's proxy. Set NODE_EXTRA_CA_CERTS before the process starts.

See E2B workload identity for the E2B side of the setup.