Skip to content

Persistent sandboxes

A persistent sandbox is one sandbox whose files outlive the container that runs it. It runs in sessions: each one up to an hour, paused after five idle minutes, and resumed with the files the last one left.

DevBoxpersistent sandboxsession 1pausedsession 25 idle minutessession()DevBoxpersistent sandboxsession 1pausedsession 25 idle minutessession()
Session 1 pauses after five idle minutes. The next call to session() starts session 2 from the files session 1 left.
src/DevBox.ts
import * as Modal from "@alchemy.run/modal";
import { Coder, Warm } from "./Coder.ts";
export const DevBox = Modal.PersistentSandbox("DevBox", { app: Coder, image: Warm, workdir: "/work" });
// construction phase
const box = yield* Modal.ConnectSandbox(DevBox);
// in fetch:
const session = yield* box.session();
const status = yield* session.exec("git status");

session() returns the running session, or resumes the box from its last session’s files.

const box = yield* sandboxes.createPersistent({ image: "node:22-bookworm" });
// store box.persistentSandboxId with the user

Persistent sandboxes are experimental on Modal: no names, GPUs, env or tags yet.