Snapshots let you save point-in-time filesystem state from a running Container. The examples on this page use the Durable Object Container API.
Container snapshots are in public beta.
Use snapshotContainer() to capture the full container filesystem. Snapshots are immutable. If you restore a snapshot and then change files, create a new snapshot to persist those changes.
The returned snapshot handle is a plain data object. You can store it and restore it later, including from another Durable Object:
import { DurableObject } from "cloudflare:workers";
export class MyDurableObject extends DurableObject {
async saveContainer() {
const containerSnapshot = await this.ctx.container.snapshotContainer({
name: "before-upgrade",
});
await this.ctx.storage.put("containerSnapshot", containerSnapshot);
}
}import { DurableObject } from "cloudflare:workers";
export class MyDurableObject extends DurableObject {
async saveContainer() {
const containerSnapshot = await this.ctx.container.snapshotContainer({
name: "before-upgrade",
});
await this.ctx.storage.put("containerSnapshot", containerSnapshot);
}
}Load the saved snapshot handle. Then, pass it to this.ctx.container.start() when you start another container:
import { DurableObject } from "cloudflare:workers";
export class MyDurableObject extends DurableObject {
async restoreContainer() {
const containerSnapshot = await this.ctx.storage.get("containerSnapshot");
if (!containerSnapshot) {
return;
}
this.ctx.container.start({ containerSnapshot, enableInternet: false });
}
}import { DurableObject } from "cloudflare:workers";
export class MyDurableObject extends DurableObject {
async restoreContainer() {
const containerSnapshot =
await this.ctx.storage.get<ContainerSnapshot>("containerSnapshot");
if (!containerSnapshot) {
return;
}
this.ctx.container.start({ containerSnapshot, enableInternet: false });
}
}Snapshots are not listed in the Cloudflare dashboard. The Container binding supports creating and restoring snapshots, but does not provide methods to list or delete them. For expiration details, refer to Understand retention.
Snapshots do not support jurisdiction selection.
Snapshots have an implicit 30-day time-to-live. Each restore refreshes that time-to-live.
You cannot set a custom time-to-live yet.
- Scheduling Policies - Choose how Container instances are configured and updated
- Durable Object Container API - Full
ctx.containerAPI reference - Lifecycle of a Container - Understand startup, sleep, and shutdown behavior