Customizing Sandbox
Custom sandboxes allows you to spawn a sandbox with a pre-defined environment by you and then control it with our SDK.
You can build a custom sandbox by creating the Sandbox Template. Sandbox template is a Dockerfile that describes the environment of your sandbox.
Once you build your custom sandbox template, you can spawn multiple isolated sandboxes from it.
How it works
-
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({ template: '<sandbox-template-id>', // You get sandbox template ID from the CLI after you run `$ e2b build` }) // Close sandbox once done await sandbox.close()
-
Run the code and we spawn a sandbox based on the template you built in step 2
Now you can do step 4/5 multiple times using the same ID, always creating a separate sandbox instance.
Read more on Sandbox Templates if you want to create your own custom sandbox.