A Snapshot saves the file system and memory state of a running sandbox, so that a new sandbox in the same state can be started from the Snapshot within seconds.
Overview
The Snapshot feature currently supports only the second-generation runtime.
A Snapshot saves the file system and memory state of a running sandbox at a specific point in time. After creation, a Snapshot is independent of its source sandbox and source template. Deleting the source sandbox or source template does not delete the Snapshot, and deleting the Snapshot does not delete the source sandbox or source template.
Typical usage: install dependencies and prepare the workspace in a sandbox, create a Snapshot, and then start new sandboxes in the same state from that Snapshot within seconds without rebuilding the template. This applies to scenarios such as resuming agent tasks from a checkpoint, warming up environments, and parallel clone exploration.
A Snapshot is retained for 7 days from creation by default and expires automatically after that. Expired Snapshots no longer appear in the list and cannot be used to create sandboxes. Snapshot retention is independent of the source sandbox lifecycle: after the source sandbox is terminated or reclaimed due to a timeout, unexpired Snapshots remain available.
Snapshot operations are called through the E2B-compatible SDK. For compatibility details, see E2B compatibility. For authentication and connection parameter configuration, see Usage constraints.
API reference
Operation | JavaScript / TypeScript | Python |
Create |
|
|
List |
|
|
Create a sandbox from a Snapshot |
|
|
Delete |
|
|
The instance method and the static method for creating a Snapshot have the same semantics. The instance method implicitly targets the current sandbox, so sandboxId / sandbox_id does not need to be passed. Listing and deletion are available only as static methods.
Return fields
Field | JavaScript | Python | Description |
Snapshot ID |
|
| UUID. Preferred when creating, deleting, or creating a sandbox from a Snapshot |
Name |
|
| Named: |
The Snapshot name and ID are independent of each other. The qualified name appears only in the names field and in name-based resolution, and does not replace the Snapshot ID.
Limits
Snapshots can be created only from a running sandbox. Creation fails if the source sandbox is paused, is creating a Snapshot, or is occupied by another operation.
Only the second-generation runtime is supported.
Named Snapshots require the current Team to have a name. If the Team has no name, only unnamed Snapshots can be created.
During creation, the
stateof the source sandbox issnapshotting, and the sandbox cannot be deleted at this point. After creation completes, the sandbox can continue to be used, or another Snapshot can be created from it.Creation can take several minutes. Set the SDK request timeout to at least 300 seconds (TypeScript:
requestTimeoutMs: 300_000; Python:request_timeout=300).timeoutMs/timeoutcontrols the sandbox lifetime, not the Snapshot request timeout. The default request timeout is typically 60 seconds; if you do not increase it, the request may fail before creation completes.The source template must still exist when the Snapshot is created. After creation succeeds, the Snapshot can still be used to restore a sandbox even if the source template is deleted later.
Create a Snapshot
name is optional. If omitted, an unnamed Snapshot is created and can be accessed only by its Snapshot ID from then on.
Within the same Team, only one available Snapshot can exist at a time for the same (short name, tag) combination, regardless of the source template. On a name conflict, creation fails without overwriting the existing Snapshot. Different tags can coexist. After deletion, the name is released immediately.
TypeScript
import { Sandbox } from "e2b";
const sandbox = await Sandbox.create("code-interpreter-v1", {
apiKey: process.env.E2B_API_KEY,
apiUrl: process.env.E2B_API_URL,
domain: process.env.E2B_DOMAIN,
timeoutMs: 300_000,
});
await sandbox.files.write("/app/state.json", '{"step": 1}');
const snapshot = await sandbox.createSnapshot({
name: "deps-ready",
requestTimeoutMs: 300_000,
});
// snapshot.snapshotId
// snapshot.names === ["demo-team/deps-ready:default"]
const another = await Sandbox.createSnapshot(sandbox.sandboxId, {
apiKey: process.env.E2B_API_KEY,
domain: process.env.E2B_DOMAIN,
requestTimeoutMs: 300_000,
name: "deps-ready:v1",
});Python
import os
from e2b import Sandbox
sandbox = Sandbox.create(
template="code-interpreter-v1",
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
timeout=300,
)
sandbox.files.write("/app/state.json", '{"step": 1}')
snapshot = sandbox.create_snapshot(
name="deps-ready",
request_timeout=300,
)
# snapshot.snapshot_id
# snapshot.names == ["demo-team/deps-ready:default"]
another = Sandbox.create_snapshot(
sandbox.sandbox_id,
name="deps-ready:v1",
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
request_timeout=300,
)Multiple Snapshots can be created from the same sandbox.
Naming rules
The qualified name format is <current Team name>/<short name>:<tag>.
Short name and tag:
^[_a-zA-Z][-_a-zA-Z0-9]*$, up to 64 characters long. Must start with a letter or an underscore.Team name prefix: identical to the Team display name, up to 32 characters long. It may start with a digit and may contain spaces, dots, underscores, and hyphens (for example, the numeric name of the default Team, or
My Team).Each segment must not contain
/or:. Neither Team names nor template names allow/, so a string that contains exactly one/can only be a Snapshot qualified name and cannot conflict with a template name.
| Result |
Omitted or empty | Unnamed. |
|
|
|
|
|
|
|
|
When creating, restoring, or deleting by name, omitting the tag is equivalent to default.
List Snapshots
Returns the Snapshots of the current Team that are neither deleted nor expired, in descending order of creation time.
If the list operation is called immediately after a successful creation, the newly written record may not appear temporarily due to indexing delay. Restoring a sandbox by Snapshot ID or qualified name, and deleting a Snapshot, are not affected. The snapshotId / names returned by the create operation can be used directly.
TypeScript
const paginator = Sandbox.listSnapshots({
apiKey: process.env.E2B_API_KEY,
domain: process.env.E2B_DOMAIN,
});
const snapshots = [];
while (paginator.hasNext) {
snapshots.push(...(await paginator.nextItems()));
}
Sandbox.listSnapshots({
apiKey: process.env.E2B_API_KEY,
domain: process.env.E2B_DOMAIN,
sandboxId: sandbox.sandboxId,
});
Sandbox.listSnapshots({
apiKey: process.env.E2B_API_KEY,
domain: process.env.E2B_DOMAIN,
name: "deps-ready",
});Python
paginator = Sandbox.list_snapshots(
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
)
snapshots = []
while paginator.has_next:
snapshots.extend(paginator.next_items())
Sandbox.list_snapshots(
sandbox_id=sandbox.sandbox_id,
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
)
Sandbox.list_snapshots(
name="deps-ready",
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
)Parameter | Description |
| Filters by source sandbox |
| When the value can be parsed as a short name or a qualified name, matching is performed segment by segment. Omitting the tag matches all tags under that name; |
| Number of entries per page. Default value: 100. Maximum value: 100 |
| Pagination cursor |
The names field of an unnamed Snapshot is empty, so name filtering does not match it. For listSnapshots / createSnapshot / deleteSnapshot static calls in TypeScript, configure E2B_API_URL through environment variables, and do not pass the unsupported apiUrl field.
Create a sandbox from a Snapshot
The template parameter of Sandbox.create can be a Snapshot ID or the qualified name of a named Snapshot. For a complete description of the creation parameters, see Create a Sandbox.
TypeScript
await Sandbox.create(snapshot.snapshotId, {
apiKey: process.env.E2B_API_KEY,
apiUrl: process.env.E2B_API_URL,
domain: process.env.E2B_DOMAIN,
timeoutMs: 300_000,
});
await Sandbox.create("demo-team/deps-ready", {
apiKey: process.env.E2B_API_KEY,
apiUrl: process.env.E2B_API_URL,
domain: process.env.E2B_DOMAIN,
timeoutMs: 300_000,
});Python
Sandbox.create(
template=snapshot.snapshot_id,
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
timeout=300,
)
Sandbox.create(
template="demo-team/deps-ready",
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
timeout=300,
)Resolution rules:
<Team name>/<short name>or<Team name>/<short name>:<tag>: treated only as a Snapshot qualified name. If it is not found, the operation fails without falling back to a template.Contains
/but is malformed: the operation fails.Does not contain
/: the value is looked up as a Snapshot ID only when it is a UUID; if that lookup misses, it is created as a template name. A regular template name that is not a UUID is created as a template directly.
Can be overridden: timeout, idle timeout, secure, allowInternetAccess, user metadata, autoPause, autoResume, network, and custom sandbox ID.
Cannot be overridden (the operation fails if passed): environment variables, volume or file system mounts, function configuration, build or image, and system metadata with the fc. prefix.
A sandbox created from a Snapshot occupies that Snapshot. Deleting the Snapshot while it is occupied fails.
Expired or deleted Snapshots cannot be used to create sandboxes. If the source template is deleted after the Snapshot is created, the Snapshot can still be used to restore a sandbox.
Delete a Snapshot
The parameter is a single string: a Snapshot ID, or a qualified name from names. Deletion returns true on success and false if the Snapshot does not exist.
Parameter | Behavior |
Snapshot ID (UUID) | Deleted by ID |
Qualified name ( | Deleted by qualified name |
Short name ( | Not deleted as a Snapshot name. The value is first looked up as an ID; if that misses, it is deleted as a template name |
Invalid qualified name (multiple | The operation fails without falling back to template deletion |
TypeScript
await Sandbox.deleteSnapshot(snapshot.snapshotId, {
apiKey: process.env.E2B_API_KEY,
domain: process.env.E2B_DOMAIN,
});
await Sandbox.deleteSnapshot(snapshot.names[0], {
apiKey: process.env.E2B_API_KEY,
domain: process.env.E2B_DOMAIN,
});Python
Sandbox.delete_snapshot(
snapshot.snapshot_id,
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
)
Sandbox.delete_snapshot(
snapshot.names[0],
api_key=os.environ["E2B_API_KEY"],
api_url=os.environ["E2B_API_URL"],
domain=os.environ["E2B_DOMAIN"],
)The Snapshot is still occupied by a restored sandbox: deletion fails.
Deleting a Snapshot does not delete the source template or the source sandbox; deleting the source sandbox or the source template does not delete the Snapshot.
When deleting by qualified name, use names[0] returned by the create or list operation, or a qualified name assembled from the current Team name. Do not pass only the short name.
Source sandbox state
| Description |
| A Snapshot is being created. Included in the default sandbox list. The sandbox cannot be deleted at this point |
| Snapshot creation failed. Not included in the default sandbox list, so you must filter by this state. The sandbox can be deleted |
After creation fails, the source sandbox can still be used or deleted.
FAQ
Condition | Result |
The source sandbox does not exist or does not belong to the current caller | Creation fails |
The sandbox runtime is not | Creation fails |
The name is invalid, or the prefix of the qualified name is not the current Team name | Creation fails |
The Team has no name but | Creation fails |
A Snapshot with the same name and tag already exists | Creation fails without overwriting |
The source sandbox is paused, is creating a Snapshot, or is occupied by another operation | Creation fails |
Environment variables, mounts, or the image are overridden when creating a sandbox from a Snapshot | Creation fails |
The Snapshot is still occupied by a restored sandbox | Deletion fails |
Restoration or deletion is performed by qualified name but the Snapshot does not exist | The operation fails without falling back to a template |
Creation times out | Creation fails, but the server may have already created the Snapshot. First increase |
Recommendations
Prefer storing the Snapshot ID returned by the create operation. For a named Snapshot, also store
names[0]to facilitate name-based restoration and deletion.Use a Snapshot when the same workspace state needs to be started repeatedly within up to 7 days. To pause a task only briefly, prefer Pause and Resume.
Promptly delete Snapshots that are no longer needed to avoid ongoing storage fees.
After restoring from a Snapshot, still call
sandbox.kill()at the end of the task to release sandbox resources.