Skip to content
All Blueprints
BLUEPRINTMulti-Agent Orchestration

Claude Agent SDK on Vercel Sandbox

Production agent deployment on Vercel Edge with secure code execution

Intermediate1 day~$200/mo
Multi-Cloud

The Problem

Building production agents with code execution is hard. Lambda times out. Docker-in-Docker is complex. Self-hosted runners require ops. You need ephemeral, isolated environments that start in milliseconds and support arbitrary code execution — plus streaming, tool calling, and MCP connectivity.

The Solution

Use Vercel Sandbox (released Jan 2026) for isolated agent execution. Deploy Next.js API routes that spawn sandboxes on demand, run Claude Agent SDK inside them, and stream results back via SSE. Each request gets a fresh isolated environment. Zero ops.

Overview

Deploy Claude Agent SDK agents to production on Vercel using Vercel Sandbox for isolated code execution. Build Claude Code-style agents that can read files, run shell commands, browse the web, and execute code — all in secure per-request sandboxes. Stream responses via SSE, handle tool calls, and scale to millions of requests on Vercel Edge.

Architecture

Loading interactive diagram...

Components

Next.js App

gateway

Vercel-hosted frontend with SSE streaming, chat UI, and real-time agent updates.

Service: Vercel Edge

Agent API Route

compute

Next.js route handler that spawns sandboxes, manages sessions, and streams responses.

Service: Vercel Serverless

Vercel Sandbox

compute

Ephemeral isolated execution environment with filesystem, shell, and network access. Spawns in milliseconds.

Service: Vercel Sandbox

Claude Agent SDK

ai-service

Running inside sandbox with tool access: read/write files, run bash, web search, MCP connections.

Service: Anthropic API

MCP Servers

gateway

Remote MCP servers for tool connectivity: GitHub, Linear, Supabase, custom tools.

Service: Various

Supabase State

database

Persistent state, user sessions, conversation history, and agent memory.

Service: Supabase

Vercel Blob

storage

File uploads and generated artifacts (reports, code, images).

Service: Vercel Blob

SSE Client

gateway

Real-time streaming to browser via EventSource for token-level updates.

Service: EventSource API

Implementation Steps

1

Setup & Sandbox

2 hours

Create Next.js app and wire up Vercel Sandbox with Claude Agent SDK

Tasks
  • Create Next.js 16 app with App Router
  • Install @vercel/sandbox and @anthropic-ai/claude-agent-sdk
  • Create /api/agent route handler
  • Initialize sandbox and run 'hello world' agent
  • Verify sandbox isolation and cleanup
Deliverables
Next.js appWorking sandboxBasic agent execution
2

Streaming & Tools

4 hours

Wire up SSE streaming, MCP connectivity, and tool call handling

Tasks
  • Implement SSE streaming in route handler
  • Add EventSource client in frontend
  • Connect MCP servers (GitHub, web search, custom)
  • Handle tool call events and stream progress
  • Test multi-turn conversations with tool use
Deliverables
SSE streamingMCP tool callsMulti-turn agent
3

Production

4 hours

Add auth, rate limiting, observability, and Supabase persistence

Tasks
  • Add Clerk or NextAuth for user authentication
  • Implement rate limiting with Upstash Redis
  • Add Supabase for session and conversation persistence
  • Configure OpenTelemetry for agent observability
  • Deploy to production and load test
Deliverables
Auth systemRate limitingPersistenceObservability

Code Examples

Agent API Route with Vercel Sandbox

Next.js route that spawns a sandbox, runs Claude Agent SDK, and streams via SSE

import { Sandbox } from '@vercel/sandbox'
import { query } from '@anthropic-ai/claude-agent-sdk'

export const runtime = 'nodejs'
export const maxDuration = 300

export async function POST(req: Request) {
  const { prompt, sessionId } = await req.json()

  const encoder = new TextEncoder()
  const stream = new ReadableStream({
    async start(controller) {
      const send = (event: string, data: any) => {
        controller.enqueue(
          encoder.encode(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`)
        )
      }

      // Spawn ephemeral sandbox
      const sandbox = await Sandbox.create({
        runtime: 'node22',
        resources: { cpu: 2, memory: 4096 },
        timeout: 300_000,
      })

      try {
        send('status', { message: 'Sandbox ready', sandboxId: sandbox.id })

        // Run Claude Agent SDK inside sandbox context
        const result = query({
          prompt,
          options: {
            cwd: sandbox.workdir,
            allowedTools: ['Read', 'Write', 'Bash', 'WebSearch'],
            mcpServers: {
              github: { url: process.env.GITHUB_MCP_URL! },
            },
            executeInSandbox: async (cmd) => sandbox.exec(cmd),
          },
        })

        for await (const message of result) {
          if (message.type === 'assistant') {
            send('token', { text: message.text })
          } else if (message.type === 'tool_use') {
            send('tool', { name: message.name, input: message.input })
          } else if (message.type === 'result') {
            send('done', { result: message.result })
          }
        }
      } finally {
        await sandbox.destroy()
        controller.close()
      }
    },
  })

  return new Response(stream, {
    headers: {
      'Content-Type': 'text/event-stream',
      'Cache-Control': 'no-cache',
      'Connection': 'keep-alive',
    },
  })
}

Cost Estimate

$200

per month

|

$2,400

per year

Vercel Pro
$20
Vercel Sandbox usage
$80
Anthropic API
$80
Supabase Pro
$20

Assumptions: ~1000 agent sessions/month, Average 5 tool calls per session, Sonnet model, Small-medium production workload

Use Cases

Production AI agents with code executionClaude Code-like hosted experiencesMulti-step autonomous research agentsCustomer support agents with tool accessDeveloper productivity agents on Vercel

Technologies

Claude Agent SDKVercel SandboxNext.js 16Vercel EdgeMCPSupabaseTypeScriptServer-Sent EventsUpstash Redis

Ready to Build?

Try the interactive prototype or get the production-ready template.