E2B Secrets keeps API keys out of AI agent sandboxes

E2B has released E2B Secrets, a feature that lets AI agents call external services without the credential ever entering the sandbox where their code runs. The company says the feature is now generally available.
- E2B Secrets is now generally available, according to E2B.
- Secrets are injected into HTTP request headers outside the sandbox, so agent code never holds the real value.
- Values are encrypted at rest and the management API is write-only for values.
- Rotating a secret updates all sandboxes that reference it, without restarts or rule changes.
- BYOC support is coming soon, and in-sandbox delivery of secrets is planned.
The problem with environment variables
Agents often need access to services that require credentials, such as a search API for a research agent or an external LLM for a document-processing workflow. According to E2B, passing a secret as an environment variable has a weakness: code running inside the sandbox can read it, print it in a log, or send it somewhere else.
E2B puts it this way: "Sandbox isolation doesn't protect a credential you've placed inside the sandbox." E2B Secrets is meant to connect agents to external services while keeping the secrets outside the code execution environment.
How request injection works
Developers store a secret with E2B, reference it by name, and configure which HTTPS destination and request headers should receive it. The agent then sends an HTTPS request without the real secret. Outside the sandbox, E2B intercepts requests that match the configured network rules, resolves the stored secret, and inserts its value into the chosen headers before forwarding the request. Values can be injected into any HTTP request header.
E2B's example has a sandbox call Claude to summarize a document. From a trusted backend, the developer stores an Anthropic API key once with the E2B SDK. The SDK connects to E2B's API over HTTPS, and TLS encrypts the secret in transit.
The sandbox is then created with network rules that allow traffic to api.anthropic.com and deny other outbound traffic. The rule tells E2B to fill the x-api-key header using Secret.fill(). This creates a reference, so the sandbox configuration contains the secret's name rather than its value.
Inside the sandbox, a curl command to the Anthropic messages endpoint contains only the prompt, the model and the API version. It needs no API key or x-api-key header. E2B adds the header after the request leaves the sandbox. According to E2B, the same pattern works for paid search APIs, other model providers, or a company's internal HTTPS services.
Storage and rotation
E2B says it stores secret values encrypted at rest. The management API is write-only for values: developers can create and update a secret, but reads and lists return only metadata. For request injection, the value is kept outside the sandbox's environment and filesystem.
Rotation is done from the backend with Secret.update(). The same stored secret can be referenced from multiple sandboxes in a project. After a rotation, subsequent matching requests from those sandboxes use the new value, without restarting sandboxes or changing their network rules. Paused sandboxes pick up the current value when they resume. Requests that already resolved the previous value can finish using it.
What comes next
Support for Bring Your Own Cloud (BYOC) is coming soon, and interested customers can contact [email protected]. E2B is also working on easier integrations with third-party services. In addition, it plans support for delivering secrets and workload tokens directly inside sandboxes, for tools that need credentials in their execution environment.
For teams building agents on E2B, the feature offers a way to give agents access to paid or internal services while limiting what sandboxed code can leak. E2B points developers to its documentation, including pages on request injection and secret rotation.
E2B: Introducing E2B Secrets


