Skip to main content
E2B templates allow you to define custom sandboxes. You can define the base image, environment variables, files to copy, commands to run, and a start command that runs during the template build and is captured in a snapshot — so the process is already running when you create a sandbox from that template. This gives you fully configured sandboxes with running processes ready to use with zero wait time for your users. There are two ways how you can start creating a new template:
  • using the CLI
  • manually using the SDK

CLI

You can use the E2B CLI to create a new template.
1

Install the E2B CLI

Install the latest version of the E2B CLI
2

Initialize a new template

3

Follow the prompts

Follow the prompts to create a new template.
4

Done

Check the generated README.md file to see how to build and use your new template.

Manual

Install the packages

Requires the E2B SDK version at least 2.3.0
Create the .env file

Create a new template file

Create a template file with the following name and content

Create a development build script

Create a production build script

Build the template

Build the development template
Build the production template

Create 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.
See Billing & limits for the full list of plan limits. Need higher limits? Contact support@e2b.dev.