- using the CLI
- manually using the SDK
CLI
You can use the E2B CLI to create a new template.Install the E2B CLI
Install the latest version of the E2B CLI
Manual
Install the packages
Requires the E2B SDK version at least 2.3.0
.env file
Create a new template file
Create a template file with the following name and contentCreate a development build script
Create a production build script
Build the template
Build the development templateCreate a new Sandbox from the Template
The template name is the identifier that can be used to create a new Sandbox.
Scaling templates
You can create a large number of templates with low overhead. It’s common to have tens or hundreds of thousands of templates, for example one template per customer, per project, or per agent run. There’s no limit on the number of templates that should discourage this pattern. Pricing for total storage used by templates will be introduced in the future. The template build environment is a full sandbox environment, so you can do anything during the build that you can do inside a running sandbox, including running Docker containers as part of the setup. Compared to snapshots, templates start faster and use fewer resources because the guest OS is restarted before the long-running process is captured and prefetching is significantly more effective. If your workload involves spinning up many per-customer or per-project environments, prefer templates over snapshots.Layering templates with fromTemplate
When you build many similar templates (e.g. a customer-specific template per customer that all share the same base setup), use fromTemplate to start from an existing template instead of rebuilding the shared layers from scratch each time. This keeps per-customer builds fast and reuses the cached base.
Build limits
Template builds are subject to the following limits:- Max build duration: Builds can run for up to 1 hour. If a build exceeds this, it will be terminated.
- Max vCPUs per build: 8 on Hobby, 8+ on Pro, custom on Enterprise.
- Max memory per build: 8 GB on Hobby, 8+ GB on Pro, custom on Enterprise.
- Max disk size per build: 10 GB on Hobby, 20+ GB on Pro, custom on Enterprise.
- Concurrent builds: 20 on Hobby and Pro, custom on Enterprise.