Vercel Sandbox guidance — ephemeral Firecracker microVMs for running untrusted code safely. Supports AI agents, code generation, and experimentation. Use when executing user-generated or AI-generated code in isolation.
Instrucciones de origen · Vista previa de solo lectura
name
vercel-sandbox
description
Vercel Sandbox guidance — ephemeral Firecracker microVMs for running untrusted code safely. Supports AI agents, code generation, and experimentation. Use when executing user-generated or AI-generated code in isolation.
[{"pattern":"from\\s+['\"\"]vm2['\"\"]|require\\s*\\(\\s*['\"\"]vm2['\"\"\\)]|new\\s+VM\\(","targetSkill":"vercel-sandbox","message":"vm2 detected — it has known security vulnerabilities. Reloading Vercel Sandbox guidance for Firecracker microVM-based safe execution."},{"pattern":"child_process.*exec\\(|execSync\\(|spawn\\(.*\\{.*shell:\\s*true","targetSkill":"ai-sdk","message":"Shell exec for code execution detected — loading AI SDK guidance for tool-calling patterns that pair with Vercel Sandbox for safe agent execution."}]
Browser Automation with Vercel Sandbox
Run agent-browser + headless Chrome inside ephemeral Vercel Sandbox microVMs. A Linux VM spins up on demand, executes browser commands, and shuts down. Works with any Vercel-deployed framework (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.).
Dependencies
pnpm add @vercel/sandbox
The sandbox VM needs system dependencies for Chromium plus agent-browser itself. Use sandbox snapshots (below) to pre-install everything for sub-second startup.
A sandbox snapshot is a saved VM image of a Vercel Sandbox with system dependencies + agent-browser + Chromium already installed. Think of it like a Docker image -- instead of installing dependencies from scratch every time, the sandbox boots from the pre-built image.
This is unrelated to agent-browser's accessibility snapshot feature (agent-browser snapshot), which dumps a page's accessibility tree. A sandbox snapshot is a Vercel infrastructure concept for fast VM startup.
Without a sandbox snapshot, each run installs system deps + agent-browser + Chromium (~30s). With one, startup is sub-second.
Creating a sandbox snapshot
The snapshot must include system dependencies (via dnf), agent-browser, and Chromium:
Pre-built sandbox snapshot ID for sub-second startup (see above)
VERCEL_TOKEN
No
Vercel personal access token (for local dev; OIDC is automatic on Vercel)
VERCEL_TEAM_ID
No
Vercel team ID (for local dev)
VERCEL_PROJECT_ID
No
Vercel project ID (for local dev)
Framework Examples
The pattern works identically across frameworks. The only difference is where you put the server-side code:
Framework
Server code location
Next.js
Server actions, API routes, route handlers
SvelteKit
+page.server.ts, +server.ts
Nuxt
server/api/, server/routes/
Remix
loader, action functions
Astro
.astro frontmatter, API routes
Example
See examples/environments/ in the agent-browser repo for a working app with the Vercel Sandbox pattern, including a sandbox snapshot creation script, streaming progress UI, and rate limiting.