Template Management

Updated at:

This page explains how to delete, get, and list templates, and how to troubleshoot template build issues. The examples use a template ID.

Prerequisites

Configure the FC Agent Sandbox API key, API URL, and domain. Replace <region> with the region that contains the template.

export E2B_API_KEY="<your-api-key>"
export E2B_API_URL="https://api.<region>.e2b.fc.aliyuncs.com"
export E2B_DOMAIN="<region>.e2b.fc.aliyuncs.com"
export TEMPLATE_ID="<template-id>"

The Python examples use the requests library:

pip install requests

Delete a template

Deletion cannot be undone. Confirm the template ID before deleting a template that may still be in use.

curl

curl --request DELETE \
  --url "${E2B_API_URL}/templates/${TEMPLATE_ID}" \
  --header "X-API-Key: ${E2B_API_KEY}"

Python requests

import os

import requests

api_url = os.environ["E2B_API_URL"].rstrip("/")
template_id = os.environ["TEMPLATE_ID"]

response = requests.delete(
    f"{api_url}/templates/{template_id}",
    headers={"X-API-Key": os.environ["E2B_API_KEY"]},
    timeout=30,
)
response.raise_for_status()
print(f"Deleted template: {template_id}")

E2B CLI

The following command asks for confirmation before deleting the template:

e2b template delete "${TEMPLATE_ID}"

In an automation script, add --yes to skip confirmation only after the script validates TEMPLATE_ID.

Get a template

The get endpoint returns template details and build records for a template ID.

curl

curl --request GET \
  --url "${E2B_API_URL}/templates/${TEMPLATE_ID}" \
  --header "X-API-Key: ${E2B_API_KEY}"

Python requests

import json
import os

import requests

api_url = os.environ["E2B_API_URL"].rstrip("/")
template_id = os.environ["TEMPLATE_ID"]

response = requests.get(
    f"{api_url}/templates/{template_id}",
    headers={"X-API-Key": os.environ["E2B_API_KEY"]},
    timeout=30,
)
response.raise_for_status()
print(json.dumps(response.json(), ensure_ascii=False, indent=2))

E2B CLI

E2B CLI does not currently provide a separate template get command. Output the template list as JSON, then use jq to select the template ID:

e2b template list --format json \
  | jq --arg template_id "${TEMPLATE_ID}" \
      '.[] | select(.templateID == $template_id)'

This command returns the list summary for the template. To retrieve template details and build records, use curl or Python requests.

List templates

The list endpoint returns templates visible to the current account in the target region.

curl

curl --request GET \
  --url "${E2B_API_URL}/templates" \
  --header "X-API-Key: ${E2B_API_KEY}"

Python requests

import json
import os

import requests

api_url = os.environ["E2B_API_URL"].rstrip("/")

response = requests.get(
    f"{api_url}/templates",
    headers={"X-API-Key": os.environ["E2B_API_KEY"]},
    timeout=30,
)
response.raise_for_status()
print(json.dumps(response.json(), ensure_ascii=False, indent=2))

E2B CLI

List templates in a table:

e2b template list

For machine-readable output, use JSON:

e2b template list --format json

Template builds

The E2B Template does not support passing steps or a Dockerfile inline; how do I build dependencies?

The Template Build API currently does not support passing steps (installation steps) or a Dockerfile inline in an E2B Template definition. Passing steps returns 400 steps are not supported, so do not try to install dependencies online through build steps.

Only this usage—passing steps or a Dockerfile inline through the E2B Template definition—is unsupported; the Dockerfile itself still works. You can still build a finished image with a Dockerfile externally, and then build the template from your image registry with from_image.

Therefore, dependencies should be installed during the Dockerfile or external image build phase, and then the finished image should be pushed to an image registry so the template only builds from that image. This avoids downloading and installing dependencies during the template build or after every Sandbox creation.

Minimal Dockerfile example:

FROM python:3.12-slim

# Install Python dependencies
RUN pip install --no-cache-dir pandas numpy

# Install system dependencies and clean the apt index
RUN apt-get update \
    && apt-get install -y --no-install-recommends git \
    && rm -rf /var/lib/apt/lists/*

Start with the error summary. If it is not sufficient to locate the failure, inspect the full build log for the failing phase, the RequestId, the image address, and the build configuration.

For the full custom image and template build flow, see Build Custom Image Templates.

How do I troubleshoot private image pull or build failures?

Identify the failing phase in the full build log, then use the following table for common source image pull and image format issues.

Failing phaseTypical errorAction
Pulling the source imageunauthorized, denied, manifest unknown, or not foundVerify that the image address, tag, or digest exists. For ACR EE, confirm that the instance and FC Agent Sandbox use the same UID and region, that a VPC reachable by the build path is bound, and that the username, password, or token is valid.
Conversion or buildinvalid image, platform of image is unknown/unknown, or manifest/provenance errorsInspect the image manifest. Build a single linux/amd64 platform image, disable provenance and SBOM, push a new tag, and retry. Do not reuse an old tag whose content may have changed.

For the full custom image template build flow, see Build Custom Image Templates; for an end-to-end example of pulling from a private registry, see Build a Sandbox Template from a GHCR Custom Image.