Skip to content

🎥 Make videos programmatically with React

store sandbox snapshots

umungobungo6b51bbc3e686
diff --git a/packages/template-vercel/.env.example b/packages/template-vercel/.env.example
index 34c10dc71b..5358ce1615 100644
--- a/packages/template-vercel/.env.example
+++ b/packages/template-vercel/.env.example
@@ -9,3 +9,8 @@
# URL of your deployed Remotion bundle (optional - if not set, will bundle on-demand)
# REMOTION_SERVE_URL=https://your-remotion-bundle.vercel.app
+
+# Sandbox Snapshot ID (optional - speeds up renders by skipping setup)
+# Create a snapshot by running: bun run create-snapshot
+# Note: Snapshots expire after 7 days
+# SANDBOX_SNAPSHOT_ID=
diff --git a/packages/template-vercel/README.md b/packages/template-vercel/README.md
index a6e6e5c4b7..cc36d3e832 100644
--- a/packages/template-vercel/README.md
+++ b/packages/template-vercel/README.md
@@ -116,6 +116,27 @@ npm run dev
5. Completed video is uploaded to Vercel Blob
6. User receives the video URL
+## Speed Up Renders with Snapshots
+
+Each fresh sandbox creation installs system dependencies, `@remotion/renderer`, and downloads headless Chrome. You can skip this setup by creating a sandbox snapshot:
+
+```bash
+bun run create-snapshot
+```
+
+This creates a pre-configured sandbox with everything installed. Copy the snapshot ID and add it to your environment:
+
+```bash
+# .env.local (for local development)
+SANDBOX_SNAPSHOT_ID=snap_xxxxx
+
+# Or add to Vercel project settings for production
+```
+
+With a snapshot, renders skip the setup phase and start rendering immediately.
+
+**Note:** Snapshots expire after 7 days. Run `bun run create-snapshot` again to create a new one.
+
## Docs
Get started with Remotion by reading the [fundamentals page](https://www.remotion.dev/docs/the-fundamentals).
diff --git a/packages/template-vercel/package.json b/packages/template-vercel/package.json
index 30978d444d..bab0951606 100644
--- a/packages/template-vercel/package.json
+++ b/packages/template-vercel/package.json
@@ -1,57 +1,58 @@
{
- "name": "template-vercel",
- "version": "0.1.0",
- "private": true,
- "author": {
- "name": "Mohit Yadav",
- "email": "[email protected]",
- "url": "https://mohitya.dev"
- },
- "scripts": {
- "dev": "next dev",
- "build": "next build",
- "start": "next start",
- "lint": "eslint .",
- "remotion": "remotion studio",
- "render": "remotion render"
- },
- "dependencies": {
- "@remotion/cli": "workspace:*",
- "@remotion/google-fonts": "workspace:*",
- "@remotion/paths": "workspace:*",
- "@remotion/player": "workspace:*",
- "@remotion/shapes": "workspace:*",
- "@remotion/tailwind-v4": "workspace:*",
- "@vercel/blob": "^2.0.1",
- "@vercel/sandbox": "^1.3.1",
- "clsx": "2.1.1",
- "next": "16.0.10",
- "react": "19.2.3",
- "react-dom": "19.2.3",
- "remotion": "workspace:*",
- "tailwind-merge": "3.0.1",
- "zod": "3.22.3"
- },
- "devDependencies": {
- "@tailwindcss/postcss": "4.1.1",
- "@remotion/eslint-plugin": "workspace:*",
- "@eslint/eslintrc": "3.1.0",
- "@eslint/js": "9.38.0",
- "@types/node": "20.12.14",
- "@types/react": "19.2.7",
- "@types/react-dom": "19.2.3",
- "@types/web": "0.0.166",
- "autoprefixer": "10.4.20",
- "dotenv": "16.0.3",
- "eslint": "9.19.0",
- "@next/eslint-plugin-next": "15.1.6",
- "eslint-config-next": "15.1.6",
- "@typescript-eslint/eslint-plugin": "8.46.0",
- "@typescript-eslint/parser": "8.46.0",
- "postcss": "8.4.47",
- "prettier": "3.6.0",
- "tailwindcss": "4.0.3",
- "typescript": "5.9.3",
- "typescript-eslint": "8.46.0"
- }
+ "name": "template-vercel",
+ "version": "0.1.0",
+ "private": true,
+ "author": {
+ "name": "Mohit Yadav",
+ "email": "[email protected]",
+ "url": "https://mohitya.dev"
+ },
+ "scripts": {
+ "dev": "next dev",
+ "build": "next build",
+ "start": "next start",
+ "lint": "eslint .",
+ "remotion": "remotion studio",
+ "render": "remotion render",
+ "create-snapshot": "bun scripts/create-snapshot.ts"
+ },
+ "dependencies": {
+ "@remotion/cli": "workspace:*",
+ "@remotion/google-fonts": "workspace:*",
+ "@remotion/paths": "workspace:*",
+ "@remotion/player": "workspace:*",
+ "@remotion/shapes": "workspace:*",
+ "@remotion/tailwind-v4": "workspace:*",
+ "@vercel/blob": "^2.0.1",
+ "@vercel/sandbox": "^1.3.1",
+ "clsx": "2.1.1",
+ "next": "16.0.10",
+ "react": "19.2.3",
+ "react-dom": "19.2.3",
+ "remotion": "workspace:*",
+ "tailwind-merge": "3.0.1",
+ "zod": "3.22.3"
+ },
+ "devDependencies": {
+ "@tailwindcss/postcss": "4.1.1",
+ "@remotion/eslint-plugin": "workspace:*",
+ "@eslint/eslintrc": "3.1.0",
+ "@eslint/js": "9.38.0",
+ "@types/node": "20.12.14",
+ "@types/react": "19.2.7",
+ "@types/react-dom": "19.2.3",
+ "@types/web": "0.0.166",
+ "autoprefixer": "10.4.20",
+ "dotenv": "16.0.3",
+ "eslint": "9.19.0",
+ "@next/eslint-plugin-next": "15.1.6",
+ "eslint-config-next": "15.1.6",
+ "@typescript-eslint/eslint-plugin": "8.46.0",
+ "@typescript-eslint/parser": "8.46.0",
+ "postcss": "8.4.47",
+ "prettier": "3.6.0",
+ "tailwindcss": "4.0.3",
+ "typescript": "5.9.3",
+ "typescript-eslint": "8.46.0"
+ }
}
diff --git a/packages/template-vercel/scripts/create-snapshot.ts b/packages/template-vercel/scripts/create-snapshot.ts
new file mode 100644
index 0000000000..3186efaafa
--- /dev/null
+++ b/packages/template-vercel/scripts/create-snapshot.ts
@@ -0,0 +1,173 @@
+/**
+ * Creates a Vercel Sandbox snapshot with all dependencies pre-installed.
+ *
+ * This script:
+ * 1. Creates a new sandbox
+ * 2. Installs system dependencies (for headless Chrome)
+ * 3. Installs @remotion/renderer
+ * 4. Downloads headless Chrome browser
+ * 5. Takes a snapshot
+ *
+ * The snapshot ID can then be used in SANDBOX_SNAPSHOT_ID env var
+ * to skip setup on future renders.
+ *
+ * https://vercel.com/docs/vercel-sandbox/concepts/snapshots
+ * Note: Snapshots expire after 7 days.
+ */
+
+import { Sandbox, Snapshot } from "@vercel/sandbox";
+
+async function createSnapshot() {
+ console.log("=== Remotion Sandbox Snapshot Creator ===\n");
+
+ // List existing snapshots
+ console.log("Checking for existing snapshots...");
+ const {
+ json: { snapshots },
+ } = await Snapshot.list();
+
+ if (snapshots.length > 0) {
+ console.log(`Found ${snapshots.length} existing snapshot(s):`);
+ for (const snap of snapshots) {
+ const expiresAt = new Date(snap.expiresAt).toLocaleDateString();
+ console.log(` - ${snap.id} (expires: ${expiresAt})`);
+ }
+ console.log("");
+ }
+
+ console.log("Creating new sandbox...");
+ const sandbox = await Sandbox.create({
+ runtime: "node24",
+ timeout: 10 * 60 * 1000,
+ });
+ console.log(`Sandbox created: ${sandbox.sandboxId}\n`);
+
+ try {
+ // Step 1: Install system dependencies for headless Chrome
+ console.log("Installing system dependencies...");
+ const sysInstallCmd = await sandbox.runCommand({
+ cmd: "sudo",
+ args: [
+ "dnf",
+ "install",
+ "-y",
+ "nss",
+ "atk",
+ "at-spi2-atk",
+ "cups-libs",
+ "libdrm",
+ "libXcomposite",
+ "libXdamage",
+ "libXrandr",
+ "mesa-libgbm",
+ "alsa-lib",
+ "pango",
+ "gtk3",
+ ],
+ detached: true,
+ });
+
+ for await (const log of sysInstallCmd.logs()) {
+ process.stdout.write(log.data);
+ }
+
+ const sysResult = await sysInstallCmd.wait();
+ if (sysResult.exitCode !== 0) {
+ throw new Error(
+ `System dependencies install failed with exit code ${sysResult.exitCode}`,
+ );
+ }
+ console.log("System dependencies installed.\n");
+
+ // Step 2: Install @remotion/renderer
+ console.log("Installing @remotion/renderer...");
+ const installCmd = await sandbox.runCommand({
+ cmd: "pnpm",
+ args: ["install", "@remotion/renderer@latest"],
+ detached: true,
+ });
+
+ for await (const log of installCmd.logs()) {
+ process.stdout.write(log.data);
+ }
+
+ const installResult = await installCmd.wait();
+ if (installResult.exitCode !== 0) {
+ throw new Error(
+ `pnpm install failed with exit code ${installResult.exitCode}`,
+ );
+ }
+ console.log("@remotion/renderer installed.\n");
+
+ // Step 3: Download headless Chrome browser
+ console.log("Downloading headless Chrome browser...");
+
+ const ensureBrowserScript = `
+const { ensureBrowser } = require("@remotion/renderer");
+
+async function main() {
+ console.log("Ensuring browser is downloaded...");
+ await ensureBrowser();
+ console.log("Browser download complete!");
+}
+
+main().catch((err) => {
+ console.error("Failed to ensure browser:", err.message);
+ process.exit(1);
+});
+`;
+
+ await sandbox.writeFiles([
+ {
+ path: "ensure-browser.cjs",
+ content: Buffer.from(ensureBrowserScript),
+ },
+ ]);
+
+ const browserCmd = await sandbox.runCommand({
+ cmd: "node",
+ args: ["ensure-browser.cjs"],
+ detached: true,
+ });
+
+ for await (const log of browserCmd.logs()) {
+ process.stdout.write(log.data);
+ }
+
+ const browserResult = await browserCmd.wait();
+ if (browserResult.exitCode !== 0) {
+ throw new Error(
+ `Browser download failed with exit code ${browserResult.exitCode}`,
+ );
+ }
+ console.log("Headless Chrome downloaded.\n");
+
+ // Step 4: Create snapshot
+ console.log("Creating snapshot...");
+ const snapshot = await sandbox.snapshot();
+
+ console.log("\n=== Snapshot Created Successfully ===");
+ console.log(`Snapshot ID: ${snapshot.snapshotId}`);
+ console.log(`Size: ${(snapshot.sizeBytes / 1024 / 1024).toFixed(2)} MB`);
+ console.log(`Expires: ${snapshot.expiresAt.toLocaleDateString()}`);
+ console.log(`\nTo use this snapshot, set the environment variable:`);
+ console.log(` SANDBOX_SNAPSHOT_ID=${snapshot.snapshotId}`);
+
+ return snapshot.snapshotId;
+ } catch (error) {
+ console.error("Error during snapshot creation:", error);
+ // Sandbox auto-stops after snapshot(), but if we error before that, clean up
+ await sandbox.stop().catch(() => {});
+ throw error;
+ }
+}
+
+createSnapshot()
+ .then(() => {
+ console.log(`\nDone! Shutting down sandbox.`);
+ process.exit(0);
+ })
+ .catch((err) => {
+ console.error("Failed to create snapshot:", err);
+ process.exit(1);
+ });
diff --git a/packages/template-vercel/src/app/api/render/route.ts b/packages/template-vercel/src/app/api/render/route.ts
index 452b2327c7..e04d26a4ac 100644
--- a/packages/template-vercel/src/app/api/render/route.ts
+++ b/packages/template-vercel/src/app/api/render/route.ts
@@ -79,6 +79,8 @@ export async function POST(req: Request) {
);
}
+ const snapshotId = process.env.SANDBOX_SNAPSHOT_ID;
+
let sandbox: Sandbox | null = null;
const encoder = new TextEncoder();
@@ -94,63 +96,81 @@ export async function POST(req: Request) {
const payload = await req.json();
const body = RenderRequest.parse(payload);
- await send({ type: "phase", phase: "Creating sandbox..." });
-
- sandbox = await Sandbox.create({
- runtime: "node24",
- timeout: 5 * 60 * 1000,
- });
-
- await send({ type: "phase", phase: "Installing system dependencies..." });
-
- const sysInstallCmd = await sandbox.runCommand({
- cmd: "sudo",
- args: [
- "dnf",
- "install",
- "-y",
- "nss",
- "atk",
- "at-spi2-atk",
- "cups-libs",
- "libdrm",
- "libXcomposite",
- "libXdamage",
- "libXrandr",
- "mesa-libgbm",
- "alsa-lib",
- "pango",
- "gtk3",
- ],
- detached: true,
- });
-
- for await (const log of sysInstallCmd.logs()) {
- await send({ type: "log", stream: log.stream, data: log.data });
- }
+ // If we have a snapshot, use it to skip setup
+ if (snapshotId) {
+ await send({
+ type: "phase",
+ phase: "Creating sandbox from snapshot...",
+ });
+
+ sandbox = await Sandbox.create({
+ source: { type: "snapshot", snapshotId },
+ timeout: 5 * 60 * 1000,
+ });
+ } else {
+ await send({ type: "phase", phase: "Creating sandbox..." });
+
+ sandbox = await Sandbox.create({
+ runtime: "node24",
+ timeout: 5 * 60 * 1000,
+ });
+
+ await send({
+ type: "phase",
+ phase: "Installing system dependencies...",
+ });
+
+ const sysInstallCmd = await sandbox.runCommand({
+ cmd: "sudo",
+ args: [
+ "dnf",
+ "install",
+ "-y",
+ "nss",
+ "atk",
+ "at-spi2-atk",
+ "cups-libs",
+ "libdrm",
+ "libXcomposite",
+ "libXdamage",
+ "libXrandr",
+ "mesa-libgbm",
+ "alsa-lib",
+ "pango",
+ "gtk3",
+ ],
+ detached: true,
+ });
+
+ for await (const log of sysInstallCmd.logs()) {
+ await send({ type: "log", stream: log.stream, data: log.data });
+ }
- const sysInstallResult = await sysInstallCmd.wait();
- if (sysInstallResult.exitCode !== 0) {
- throw new Error(
- `System dependencies install failed: ${await sysInstallResult.stderr()}`,
- );
- }
+ const sysInstallResult = await sysInstallCmd.wait();
+ if (sysInstallResult.exitCode !== 0) {
+ throw new Error(
+ `System dependencies install failed: ${await sysInstallResult.stderr()}`,
+ );
+ }
- await send({ type: "phase", phase: "Installing renderer..." });
+ await send({ type: "phase", phase: "Installing renderer..." });
- const installCmd = await sandbox.runCommand({
- cmd: "pnpm",
- args: ["install", "@remotion/renderer@latest"],
- detached: true,
- });
+ const installCmd = await sandbox.runCommand({
+ cmd: "pnpm",
+ args: ["install", "@remotion/renderer@latest"],
+ detached: true,
+ });
- for await (const log of installCmd.logs()) {
- await send({ type: "log", stream: log.stream, data: log.data });
- }
+ for await (const log of installCmd.logs()) {
+ await send({ type: "log", stream: log.stream, data: log.data });
+ }
- const installResult = await installCmd.wait();
- if (installResult.exitCode !== 0) {
- throw new Error(`pnpm install failed: ${await installResult.stderr()}`);
+ const installResult = await installCmd.wait();
+ if (installResult.exitCode !== 0) {
+ throw new Error(
+ `pnpm install failed: ${await installResult.stderr()}`,
+ );
+ }
}
await send({ type: "phase", phase: "Rendering video..." });