Templates
A template is what a miniVM starts from: a disk and a memory snapshot, built from a minisandbox.yaml recipe. Your tools are installed, your service is already running, and every new miniVM starts from that point.
Templates belong to your organization. Every build makes a new immutable version (v1, v2…). A miniVM always keeps the version it started from.
Base templates
Section titled “Base templates”Start your recipe from: one of these, or from your own image or Dockerfile.
| Template | What it holds |
|---|---|
dev-base |
Ubuntu 24.04, git, the GitHub CLI gh, build tools, and Docker (the daemon is running in the snapshot; user is in the docker group). Egress presets: ubuntu, github, docker-hub, ghcr, pypi, npm, crates. |
dev-agents |
dev-base plus Node.js, pnpm, Python 3.12, uv, Rust, and the coding agents Claude Code, Codex and OpenCode. Egress presets: those of dev-base plus llm-apis (the model APIs and Claude sign-in). It is the base of agent runs. |
Every field of a recipe is described in the minisandbox.yaml reference.
What dev-agents puts on the PATH
Section titled “What dev-agents puts on the PATH”- Node.js 26 is in
/opt/node/bin. - The coding agents and the pnpm they use (a recent major) are in
/home/user/.agents-tools/node_modules/.bin, first on thePATH. A project that pins another pnpm in itspackageManagerfield gets that pnpm only if you put it first: run it withnpx pnpm@<version>, or install it insetupto a directory you put ahead on thePATHin your recipe’senv. sudokeeps its ownPATH, without/opt/node/bin:sudo npmanswerscommand not found. Call Node tools withoutsudo, or by their full path (sudo /opt/node/bin/npm).
On the managed service, base templates are bases for your recipes, not templates you run: a create (ons create --template, Sandbox.create) names a template of your organization. ons create and the E2B SDKs use your organization’s template base when you name none. It is requested when you sign up, and built once your organization can run builds. On a Hybrid pool, you run the public templates dev-base and dev-agents directly.
Network access of the base template
Section titled “Network access of the base template”Your organization’s base template reaches the package registries and nothing else: Ubuntu
(apt-get), PyPI (pip), npm and crates.io (cargo), the presets ubuntu, pypi, npm and
crates. So apt-get install and pip install work in a miniVM created with no template. The
template has Python but not Node.js or Rust: install them first
(sudo apt-get install -y nodejs npm, sudo apt-get install -y cargo), then npm install and
cargo build reach their registries. GitHub, Docker Hub and every other host are refused
until you allow them. Add them when you create the miniVM:
ons create --json --template base --egress-add githubfrom e2b import Sandbox
sbx = Sandbox.create(network={"allow_out": [ "pypi.org", "files.pythonhosted.org", "github.com", "api.github.com",]})import { Sandbox } from 'e2b'
const sbx = await Sandbox.create({ network: { allowOut: ['pypi.org', 'files.pythonhosted.org', 'github.com', 'api.github.com'] },})--egress-addadds to what the template allows. It takes presets (github,docker-hub,ghcr,llm-apis, …) or domain names. See Presets for the hosts of each preset.network.allowOutsets the miniVM’s whole list, by domain name: the template’s names it does not repeat are closed. Name the registries you still need, as above for PyPI.- On a running miniVM, run
ons egress allow <minivm-id> github.<minivm-id>is the idons createprinted. - A name that is not allowed fails as a DNS error inside the miniVM (“Temporary failure in name
resolution”). To see which names were refused, within about a minute:
ons egress denials <minivm-id>, or, withoutons,GET /v2/sandboxes/<minivm-id>/egress/denialswith your API key: see See what a miniVM was refused. With the E2B SDK,<minivm-id>issbx.sandbox_id(sbx.sandboxIdin JavaScript). --egress-allowonly narrows to names the template already allows. Use--egress-add, which adds names up to your organization’s ceiling.- Templates you build yourself keep the rule: their egress is closed unless their recipe lists it. See Egress.
- An organization created before 30 November 2026 keeps the
basebuilt for it, which may allow less, often no egress at all.ons egress ls <minivm-id>shows what a miniVM allows. Add the registries when you create the miniVM:ons create --template base --egress-add ubuntu --egress-add pypi --egress-add npm --egress-add crates.
Build your first template
Section titled “Build your first template”Write a recipe
In the root of your project, run:
Terminal window ons template initIt writes a minimal
minisandbox.yamlnamed after the directory:from: dev-base, ordockerfile: ./Dockerfilewhen the directory has a Dockerfile. Then edit it. For example:minisandbox.yaml version: 1name: my-apifrom: dev-agentsresources:vcpu: 2memory: 4GiBfiles:- src: .dest: /home/user/appignore: [node_modules, .git]workdir: /home/user/appsetup:- uv venv && uv pip install -r requirements.txtstart:cmd: .venv/bin/python -m http.server 8000ready:http: http://localhost:8000/egress:presets: [pypi, github]ports: [8000]Every field is described in the minisandbox.yaml reference.
Check it offline
Terminal window ons template validateons template build --dry-runErrors name the file, line and column, and what to do:
minisandbox.yaml:12:3: unknown field `setpu` · did you mean `setup`?Build it
Terminal window ons template buildonspacks and uploads the files the recipe copies, starts the build and follows its logs to the end. Pass--no-waitto return once the build is queued, then follow it later:Terminal window ons template logs <build-id><build-id>is the idons template buildprinted.Start a miniVM from it
Terminal window ons create --template my-apiWith the E2B SDK, pass the name as the template:
Sandbox.create("my-api")in Python,Sandbox.create('my-api')in JavaScript.
What a build does
Section titled “What a build does”- Source. It pulls the
image, builds thedockerfile, or starts from thefromtemplate’s disk. Images come from public registries. - Files. It copies each
filesitem to itsdest, and creates the recipe’suser(defaultuser) if the image lacks it: seeuser. - Setup. It boots a miniVM with the recipe’s resources and egress, and runs
setupline by line. A non-zero exit fails the build. - Snapshot. It starts
start, waits for itsreadycheck, then snapshots memory and disk. - Publish. The new version becomes
readyand current.
A failed build publishes nothing: the current version stays as it was. Build logs say which phase failed and why.
Writing setup
Section titled “Writing setup”- Each line runs in its own shell, as the recipe’s
user(defaultuser, with passwordlesssudo). Join commands that share variables or a directory on one line. - Services do not start during
setup. Package installs cannot start daemons in a build (invoke-rc.d: policy-rc.d denied execution of start). To have a service such as PostgreSQL running in every miniVM, start it instart, with areadycheck: it is running in the snapshot, so each miniVM starts with it. - Install packages with
--no-install-recommends. A recommended package can break the miniVM’s network. For examplesystemd-resolvedreplaces/etc/resolv.confwith a link that does not exist in a miniVM, and every name lookup then fails withTemporary failure in name resolution(EAI_AGAIN), with nothing inons egress denials. If a package must bring it, restore the file at the end ofsetup. - A host
setupneeds must be in the recipe’segress. The build reaches only what the recipe allows.
The files you send for a build are deleted within 7 days. The recipe and the built image stay with the version.
When nothing that changes the disk has changed since a ready version, the build reuses that version’s result instead of building again. If only start, resources, ports or lifecycle changed, the build is refused with 409: a rebuild of the snapshot alone is not available yet. Change setup or files to build again, or keep that version’s values.
Faster Ubuntu packages in builds
Section titled “Faster Ubuntu packages in builds”On the managed service, template builds cache Ubuntu packages fetched over HTTP from
snapshot.ubuntu.com: the RUN lines of a dockerfile: and the setup lines of every recipe.
miniVMs started from the template later do not use that cache. A plain apt-get --snapshot <date>
does not use it either: apt fetches the snapshot over HTTPS. Point the snapshot at the HTTP address
to use it, in one line, since each setup line runs in its own shell:
setup: - snapshot="--snapshot 20261117T000000Z -o Acquire::Snapshots::URI::Override::Origin::Ubuntu=http://snapshot.ubuntu.com/ubuntu/@SNAPSHOTID@/" && sudo apt-get update $snapshot && sudo apt-get install -y $snapshot <package><package>is the Ubuntu package to install, for exampleffmpeg.20261117T000000Zis a snapshot id: a UTC time asYYYYMMDDTHHMMSSZthat Ubuntu has published, such as this one, whichdev-basewas built with.- In a Dockerfile
RUNline, write the same line withoutsudo: it runs as root.
apt still checks the signed Release files and the hash of every package, over HTTP as over HTTPS.
The recipe needs the ubuntu egress preset (or snapshot.ubuntu.com in its allow list):
without it, the name does not resolve during the build and apt reports that it cannot resolve
snapshot.ubuntu.com.
Versions and rollback
Section titled “Versions and rollback”ons template lsons template versions my-apions template rollback my-api <version>lslists your organization’s templates with their current version.versionslists the versions of one template, each with its status and digest. The current one is marked*.rollbackmakes an older ready version current again.<version>is its number or its id, fromons template versions.
New miniVMs start from the current version. Running and paused miniVMs keep theirs.
A version that is no longer current is deleted 90 days after it stopped being current, once no miniVM or paused miniVM uses it.
In the console
Section titled “In the console”Templates in the console lists your organization’s templates with their version, size and status. Build history shows a template’s builds and their logs. When the base template the service builds for a new organization failed, Retry asks for that build again (for example, after you add a payment method). Build your own templates with ons.
Several templates in one repository
Section titled “Several templates in one repository”Keep one recipe per template, for example in .minisandbox/<name>.yaml, and pass it with --file:
ons template build --file .minisandbox/<name>.yaml<name> is the template’s file name. Paths in files and dockerfile are relative to the recipe’s own directory.
Keep secrets out of templates
Section titled “Keep secrets out of templates”Everything in a template is copied into every miniVM started from it. Never put a secret in env, files, setup or a Dockerfile ARG, and never run gh auth login or a similar sign-in in setup: the token would be frozen in every snapshot.
Pass credentials when you create the miniVM instead. Environment variable values you pass at create are not stored: they are kept only while the miniVM runs. env values in a recipe are stored with the template version. Egress credentials add a secret header to the miniVM’s outbound requests without the miniVM ever seeing it.
With a Dockerfile, ons warns when the build context holds .git or a .env* file. Add them to .dockerignore.
Limits
Section titled “Limits”- Recipe: 256 KiB.
- Files a build uploads: 2 GiB and 100 000 entries, after
ignore. start.ready.timeout: at most 10 minutes.- Builds per organization and per key are rate limited. See Quotas and limits.