E2B guide: safely run AI-generated code in isolated sandboxes
Brief
E2B’s guide outlines isolation and access controls for teams running code written by AI agents. It includes working examples for sandbox timeouts, network restrictions, cleanup, and credential injection.
Recommended safeguards
- Give each user session its own sandbox and kernel; do not place secrets where generated code can read them.
- Deny outbound traffic by default and allow only required destinations; disable public inbound traffic.
- Set execution and sandbox timeouts, then destroy the sandbox in a
finallyblock.
Implementation details
- The guide provides Python and JavaScript examples that disable internet access and use a 60-second sandbox lifetime with a 20-second per-run timeout.
- For API access, E2B’s egress proxy can inject a stored secret into requests to an allowed host, keeping its value outside the sandbox; the destination still receives the credential.
- E2B says sandboxes use Firecracker microVMs with separate kernels. Stored secrets and Workload Identity are generally available on E2B Cloud, while per-host request transforms are in public beta.
Generated by AI from the original article. Check the source for full details.