GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Guide
  • Examples
  • Log in
  • Sign up

This view

  • Original page
  • New address

GeezerVison is showing modal.com — Sandbox Exit Snapshots

Guide Introduction to Modal Getting started Functions Functions Invocation methods Function lookups Container lifecycle management Parametrized Functions Dynamic configuration Sandboxes Sandboxes Running commands Networking and security File access Snapshots Exit Snapshots BetaPricing and resources Sidecars BetaSecret injection BetaModel APIs Model APIs Models and pricing Agent integrations Endpoints Endpoints Supported models Candidates Training Quickstart Tinker-compatible API BetaMulti-node training Images Defining Images Using existing container images Named images Fast pull from registry GPUs and other resources GPU acceleration Using CUDA on Modal Configuring CPU, memory, and disk Scaling out Scaling out Input concurrency Batch processing Job queues Dynamic batching Multi-node Clusters Deployment Apps, Functions, and entrypoints Managing deployments Continuous deployment Scheduled Functions Observability HTTP Applications Servers Sticky Sessions Web Functions Streaming endpoints Web Function URLs Request timeouts Proxy Tokens Networking Tunnels Proxies BetaCluster networking Data sharing and storage Passing local data Volumes Storing model weights Cloud bucket mounts Dicts Queues Dataset ingestion Secrets and environment variables Secrets Environment variables Performance Cold start performance Memory Snapshots High-performance LLM inference Reliability and robustness Failures and retries Preemption Timeouts GPU health Troubleshooting Security and privacy Security and privacy Data residency Customer-supplied encryption keys AlphaAudit logs Integrations Using OIDC to authenticate with external services Connecting Modal to your Datadog account Connecting Modal to your OpenTelemetry provider Slack notifications Workspace & account settings Workspaces Environments Service users User groups Role-Based Access Control (RBAC) Billing Network egress billing Budgets Identity and provisioning Okta SSO Microsoft Entra SSO Google Workspace SSO Custom SAML SSO SCIM Integration Other topics Feature maturity Restricted Functions JavaScript/Go SDKs BetaModal 1.0 migration guide File and project structure Developing and debugging Jupyter notebooks Asynchronous API usage Global variables Region selection Localized placement GPU Metrics Search syntax

Sandbox Exit Snapshots

Beta
This feature is in Beta.

Exit snapshots do not guarantee that a Sandbox’s filesystem will be persisted in cases of rare hardware failures. If you need stronger durability guarantees, consider using Volumes.

We'd love to hear your feedback — please reach out via Slack or email us at [email protected].

Exit Snapshots take a filesystem snapshot automatically on both graceful and ungraceful Sandbox exits, including terminate(), entrypoint completion, idle timeout, lifetime expiry, and OOM.

This is useful when you want filesystem state after a Sandbox is gone without having to snapshot the filesystem yourself first. Typical uses:

  • Resuming an agent or coding session after an idle timeout
  • Recovering work from a Sandbox that exited unexpectedly
  • Avoiding races between your own teardown and an in-flight manual snapshot

Usage 

Opt in at time of creation by setting enable_exit_snapshot in the experimental options, then fetch the resulting Image after the Sandbox has exited:

import modal

app = modal.App.lookup("exit-snapshot-example", create_if_missing=True)

sb = modal.Sandbox.create(
    "bash",
    "-c",
    "echo hello > /tmp/marker.txt",
    app=app,
    experimental_options={"enable_exit_snapshot": True},
)
sb.wait()

image = sb._experimental_get_exit_snapshot()
restored = modal.Sandbox.create(app=app, image=image)
print(restored.filesystem.read_text("/tmp/marker.txt"))  # "hello\n"
restored.terminate()
import { ModalClient } from "modal";

const modal = new ModalClient();
const app = await modal.apps.fromName("exit-snapshot-example", {
  createIfMissing: true,
});
const image = modal.images.fromRegistry("python:3.13-slim");

const sb = await modal.sandboxes.create(app, image, {
  command: ["bash", "-c", "echo hello > /tmp/marker.txt"],
  experimentalOptions: { enable_exit_snapshot: true },
});
await sb.wait();

const snapshot = await sb.experimentalGetExitSnapshot();
const restored = await modal.sandboxes.create(app, snapshot);
console.log(await restored.filesystem.readText("/tmp/marker.txt")); // "hello"
await restored.terminate();
package main

import (
	"context"
	"fmt"

	modal "github.com/modal-labs/modal-client/go"
)

func main() {
	ctx := context.Background()
	mc, _ := modal.NewClient()

	app, _ := mc.Apps.FromName(ctx, "exit-snapshot-example", &modal.AppFromNameParams{
		CreateIfMissing: true,
	})
	image := mc.Images.FromRegistry("python:3.13-slim", nil)

	sb, _ := mc.Sandboxes.Create(ctx, app, image, &modal.SandboxCreateParams{
		Command:             []string{"bash", "-c", "echo hello > /tmp/marker.txt"},
		ExperimentalOptions: map[string]any{"enable_exit_snapshot": true},
	})
	sb.Wait(ctx, nil)

	snapshot, _ := sb.ExperimentalGetExitSnapshot(ctx, nil)
	restored, _ := mc.Sandboxes.Create(ctx, app, snapshot, nil)
	text, _ := restored.Filesystem.ReadText(ctx, "/tmp/marker.txt", nil)
	fmt.Println(text) // "hello"
	restored.Terminate(ctx, nil)
}

You can also reconnect to the Sandbox later by ID and fetch the exit snapshot from that handle. This is useful when the create and resume happen in different processes:

import modal

app = modal.App.lookup("exit-snapshot-example", create_if_missing=True)

# Process A: create a Sandbox, do work, then let it idle out or terminate.
sb = modal.Sandbox.create(
    app=app,
    experimental_options={"enable_exit_snapshot": True},
)
sb.filesystem.write_text("session state", "/workspace/state.txt")
sandbox_id = sb.object_id
sb.terminate(wait=True)

# Process B: resume from the exit snapshot.
sb = modal.Sandbox.from_id(sandbox_id)
image = sb._experimental_get_exit_snapshot()
sb2 = modal.Sandbox.create(app=app, image=image)
print(sb2.filesystem.read_text("/workspace/state.txt"))  # "session state"
sb2.terminate()
// Process A: create a Sandbox, do work, then let it idle out or terminate.
const sb = await modal.sandboxes.create(app, image, {
  experimentalOptions: { enable_exit_snapshot: true },
});
await sb.filesystem.writeText("session state", "/workspace/state.txt");
const sandboxId = sb.sandboxId;
await sb.terminate({ wait: true });

// Process B: resume from the exit snapshot.
const sb1 = await modal.sandboxes.fromId(sandboxId);
const snapshot = await sb1.experimentalGetExitSnapshot();
const sb2 = await modal.sandboxes.create(app, snapshot);
console.log(await sb2.filesystem.readText("/workspace/state.txt")); // "session state"
await sb2.terminate();
// Process A: create a Sandbox, do work, then let it idle out or terminate.
sb, _ := mc.Sandboxes.Create(ctx, app, image, &modal.SandboxCreateParams{
	ExperimentalOptions: map[string]any{"enable_exit_snapshot": true},
})
sb.Filesystem.WriteText(ctx, "session state", "/workspace/state.txt", nil)
sandboxID := sb.SandboxID
sb.Terminate(ctx, &modal.SandboxTerminateParams{Wait: true})

// Process B: resume from the exit snapshot.
sb, _ = mc.Sandboxes.FromID(ctx, sandboxID, nil)
snapshot, _ := sb.ExperimentalGetExitSnapshot(ctx, nil)
sb2, _ := mc.Sandboxes.Create(ctx, app, snapshot, nil)
text, _ := sb2.Filesystem.ReadText(ctx, "/workspace/state.txt", nil)
fmt.Println(text) // "session state"
sb2.Terminate(ctx, nil)

Waiting for the snapshot 

Fetching the exit snapshot long-polls until the snapshot reaches a terminal state. The timeout parameter controls how long to wait:

TimeoutBehavior
Unset (default)Wait until the snapshot succeeds or fails
0Immediate check; fails with TimeoutError if pending
> 0Wait up to the specified duration

On success, the method returns an Image you can use to create a new Sandbox.

Errors 

Fetching the exit snapshot can fail with these errors:

ErrorWhen
SnapshotCreationErrorSnapshot creation failed
TimeoutErrorStill pending when your timeout elapses
InvalidErrorExit snapshots were not enabled on the Sandbox, or the timeout is negative
NotFoundErrorThe Sandbox no longer exists

In Python these are all modal.exception classes. Note that TimeoutError is Modal’s own class rather than Python’s builtin, so a bare except TimeoutError will not catch it.

Retention 

Exit snapshot Images are retained for 30 days after creation, matching the default for filesystem snapshots. After that, attempting to use the Image fails with NotFoundError.

Limitations 

  • Filesystem only. Exit Snapshots capture the Sandbox filesystem, not memory or directory mounts.
  • Main container only. Sidecar containers are not included.
  • Maximum 256 GiB of changed file data per snapshot. This limit applies to the combined size of files the snapshot needs to process.
  • Preemption is not covered. GPU Sandboxes may run on preemptible capacity, and a preempted host generally does not give the Sandbox enough time to take an exit snapshot. This only affects GPU Sandboxes - CPU Sandboxes are not preemptible. If you rely on exit snapshots for GPU Sandboxes, also snapshot the filesystem periodically.
  • Snapshot failure loses that Sandbox’s filesystem state. If you need to periodically persist state with stronger durability guarantees, prefer Volumes.
Sandbox Exit SnapshotsUsageWaiting for the snapshotErrorsRetentionLimitations
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.