Vercel Sandboxes
Run commands in isolated Vercel environments with either persistent Sandbox microVMs or stateless Serverless Functions.
Vercel SandboxVercel Sandbox的直接链接
Executes commands inside Vercel Sandbox which is an ephemeral Firecracker MicroVM running Amazon Linux 2023. Provides a persistent in-session filesystem, sudo access, exposed ports, and background processes. For interface details, see the WorkspaceSandbox interface.
This is distinct from VercelServerlessSandbox, which runs commands as stateless Vercel serverless Functions. VercelSandbox runs a full Linux MicroVM with a persistent filesystem and long-running processes.
InstallationInstallation的直接链接
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/vercel
pnpm add @mastra/vercel
yarn add @mastra/vercel
bun add @mastra/vercel
AuthenticationAuthentication的直接链接
The @vercel/sandbox SDK uses a Vercel OIDC token automatically when no explicit credentials are provided. If you provide token, teamId, or projectId, provide all three values together.
- OIDC (recommended)
- Access token (.env)
- Constructor
For local development, link the project and pull a development token:
vercel link
vercel env pull
On Vercel, authentication is handled automatically — no configuration needed.
For environments without OIDC, provide all three values together:
VERCEL_TOKEN=your-token
VERCEL_TEAM_ID=your-team-id
VERCEL_PROJECT_ID=your-project-id
new VercelSandbox({
token: 'your-token',
teamId: 'your-team-id',
projectId: 'your-project-id',
})
UsageUsage的直接链接
Add a VercelSandbox to a workspace and assign it to an agent:
import { Agent } from '@mastra/core/agent'
import { Workspace } from '@mastra/core/workspace'
import { VercelSandbox } from '@mastra/vercel'
const workspace = new Workspace({
sandbox: new VercelSandbox({
runtime: 'node24',
timeout: 600_000,
}),
})
const agent = new Agent({
id: 'code-agent',
name: 'Code Agent',
instructions: 'You are a coding assistant working in this workspace.',
model: 'anthropic/claude-sonnet-4-6',
workspace,
})
const response = await agent.generate('Print "Hello, world!" and show the Node.js version.')
console.log(response.text)
Resources and exposed portsResources and exposed ports的直接链接
Allocate vCPUs (2048 MB of memory per vCPU) and expose ports to reach network services running inside the sandbox:
const sandbox = new VercelSandbox({
runtime: 'node24',
resources: { vcpus: 4 },
ports: [3000],
})
const workspace = new Workspace({ sandbox })
await sandbox.start()
// The public HTTPS domain for an exposed port is available via getInfo()
const { metadata } = sandbox.getInfo()
console.log(metadata?.domains) // { 3000: 'https://....vercel.run' }
Streaming outputStreaming output的直接链接
Stream command output in real time via onStdout and onStderr callbacks:
await sandbox.executeCommand('sh', ['-c', 'for i in 1 2 3; do echo "line $i"; sleep 1; done'], {
onStdout: chunk => process.stdout.write(chunk),
onStderr: chunk => process.stderr.write(chunk),
})
Both callbacks are optional and can be used independently.
Constructor parametersConstructor parameters的直接链接
id?:
sandboxName?:
token?:
teamId?:
projectId?:
runtime?:
timeout?:
resources?:
ports?:
env?:
workingDirectory?:
cwd is given. A per-command cwd always wins. Use an absolute path.metadata?:
instructions?:
onStart?:
running status.onStop?:
onDestroy?:
PropertiesProperties的直接链接
id:
name:
provider:
status:
sandbox:
processes:
Background processesBackground processes的直接链接
VercelSandbox includes a process manager for spawning and managing background processes. Each spawned process runs as a detached command inside the MicroVM, with output streamed through the command logs.
const sandbox = new VercelSandbox({ runtime: 'node24', ports: [3000] })
await sandbox.start()
const handle = await sandbox.processes.spawn('node server.js', {
env: { PORT: '3000' },
onStdout: data => console.log(data),
})
console.log(handle.stdout)
await handle.kill()
See the SandboxProcessManager reference for the full API.
The Vercel Sandbox SDK doesn't expose a stdin channel for running commands, so handle.sendStdin() throws. Filesystem mounting (FUSE) is also not supported by this provider.
LimitsLimits的直接链接
- Up to 32 vCPUs, with 2048 MB of memory per vCPU.
- Up to 15 exposed ports.
- The filesystem is ephemeral. It's persisted only within the session and lost when the sandbox stops.
- Maximum runtime is plan-dependent (45 minutes on Hobby, up to 24 hours on Pro and Enterprise), with a default of 5 minutes.
See the Vercel Sandbox documentation for current limits and pricing.
Vercel Serverless SandboxVercel Serverless Sandbox的直接链接
VercelServerlessSandbox executes commands as Vercel serverless functions. It provides globally distributed, zero-infrastructure execution with automatic scaling. For interface details, see the WorkspaceSandbox interface.
VercelServerlessSandbox is stateless. It doesn't provide a persistent filesystem, interactive shell, or long-running background processes. Only /tmp is writable, and it's ephemeral between invocations.
For a full Linux MicroVM with a persistent filesystem, sudo access, exposed ports, and background processes, use VercelSandbox, which is backed by the Vercel Sandbox product.
InstallationInstallation的直接链接
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/vercel
pnpm add @mastra/vercel
yarn add @mastra/vercel
bun add @mastra/vercel
UsageUsage的直接链接
Add a VercelServerlessSandbox to a workspace and assign it to an agent:
import { Agent } from '@mastra/core/agent'
import { Workspace } from '@mastra/core/workspace'
import { VercelServerlessSandbox } from '@mastra/vercel'
const workspace = new Workspace({
sandbox: new VercelServerlessSandbox({
token: process.env.VERCEL_TOKEN,
}),
})
const agent = new Agent({
id: 'dev-agent',
name: 'dev-agent',
instructions: 'You are a coding assistant working in this workspace.',
model: 'anthropic/claude-sonnet-4-6',
workspace,
})
Team-scoped deployment with custom resourcesTeam-scoped deployment with custom resources的直接链接
const workspace = new Workspace({
sandbox: new VercelServerlessSandbox({
token: process.env.VERCEL_TOKEN,
teamId: 'team_abc123',
regions: ['iad1', 'sfo1'],
maxDuration: 120,
memory: 3008,
env: {
NODE_ENV: 'production',
},
}),
})
Constructor parametersConstructor parameters的直接链接
token?:
VERCEL_TOKEN environment variable.teamId?:
projectName?:
regions?:
maxDuration?:
memory?:
env?:
workingDirectory?:
cwd is given. A per-command cwd always wins. When omitted, commands fall back to /tmp and sandbox.workingDirectory stays undefined.commandTimeout?:
instructions?:
getInstructions(). Pass a string to fully replace, or a function to extend the defaults.onStart?:
running status.onStop?:
onDestroy?:
PropertiesProperties的直接链接
id:
name:
provider:
status:
'pending', 'starting', 'running', 'stopping', 'stopped', 'destroying', 'destroyed', or 'error'.LimitationsLimitations的直接链接
VercelServerlessSandbox uses serverless functions under the hood, which means:
- No persistent filesystem: Files written to
/tmpare ephemeral and cleared between invocations. - No interactive shell: Commands run via
/bin/sh -cwith no stdin streaming. - No background processes: No process manager, PIDs, or long-running tasks.
- No mounting: Cloud storage mounting (S3, GCS) isn't supported.
- Timeout limits: Maximum execution time is bounded by
maxDuration(default 60s).
RelatedRelated的直接链接
- WorkspaceSandbox interface
- Workspace class
- E2B sandbox: Full-featured cloud sandbox with persistent filesystem and process management