Custom Sandbox
Custom sandboxes allow you to spawn a sandbox with an environment predefined by you and then control it with our SDK.
The E2B Sandbox is a secure way to run your AI app. It is a long-running cloud environment where you can let any LLM (GPTs, Claude, local LLMs, etc) use tools exactly like you would do locally.
Read more about E2B Sandboxes here.
How Custom Sandboxes Work
Follow our guide on how to create a custom sandbox.
-
You build a custom sandbox by creating the Sandbox Template which is a Dockerfile describing the environment of your sandbox.
-
Build a sandbox template from it using our CLI
-
Get a template ID from the CLI:
# ... truncated CLI output ✅ Building sandbox template 3y5bvra6kgq0kaumgztu finished.
-
Pass the template ID to our SDK like this:
Using custom sandbox with SDK
import { Sandbox } from 'e2b' // Create new sandbox const sandbox = await Sandbox.create({ // You get sandbox template from the CLI after you run `$ e2b build` template: '<sandbox-template>', }) // Close sandbox once done await sandbox.close()
-
Run the code and we spawn a sandbox based on the template you built in step 2
Once you build your custom sandbox template, you can spawn multiple isolated sandboxes from it. You can repeat the steps 4, 5 multiple times using the same ID, always creating a separate sandbox instance.
Follow our guide on how to create a custom sandbox.