Can I deploy OpenCode to Vercel with Sandbox?
can i deploy opencode to vercel? if i use the opencode SDK alongside vercel sandbox? https://vercel.com/docs/vercel-sandbox
or what would be the recommended setup?
Now I have a complete picture. Let me summarize what I've found:
##Summary: Running OpenCode with Vercel Sandbox
Short answer: It's possible but requires significant setup work. Here's why:
###The Challenge
OpenCode is a full coding agent that requires:
- Bun runtime - OpenCode's server uses
Bun.serve()(packages/opencode/src/server/server.ts:2873) - File system access - Full read/write access for code editing, snapshots, LSP, etc.
- Shell/bash execution - The core
bashtool spawns shell commands (packages/opencode/src/tool/bash.ts) - LSP servers - For intelligent code features
- Persistent storage - Sessions, configuration, worktrees
###Vercel Sandbox Limitations
From the Vercel Sandbox docs:
- Runtimes available:
node22,node24,python3.13- No Bun runtime - Base system: Amazon Linux 2023
- You CAN: Install packages via
dnf, run arbitrary commands withsudo, have file system access in/vercel/sandbox - Timeout: Max 5 hours (Pro/Enterprise) or 45 minutes (Hobby)
###Recommended Setup Options
####Option 1: Run OpenCode in Vercel Sandbox (Complex)
You could install Bun inside the sandbox and run OpenCode:
import { Sandbox } from '@vercel/sandbox';
import ms from 'ms';
const sandbox = await Sandbox.create({
runtime: 'node22', // Use node as base
resources: { vcpus: 4 },
timeout: ms('1h'),
ports: [4096],
});
// Install Bun
await sandbox.runCommand({
cmd: 'curl',
args: ['-fsSL', 'https://bun.sh/install', '|', 'bash'],
sudo: true,
});
// Install OpenCode
await sandbox.runCommand({
cmd: 'npm',
args: ['i', '-g', 'opencode-ai'],
});
// Start OpenCode server
await sandbox.runCommand({
cmd: 'opencode',
args: ['serve', '--hostname=0.0.0.0', '--port=4096'],
detached: true,
env: {
ANTHROPIC_API_KEY: '...',
OPENCODE_SERVER_PASSWORD: '...',
}
});
// Connect via SDK
const client = createOpencodeClient({
baseUrl: sandbox.domain(4096),
});
####Option 2: Use the OpenCode SDK Differently (Simpler)
The OpenCode SDK (packages/sdk/js/src/server.ts) spawns the opencode binary locally. For a cloud setup, you'd:
- Deploy OpenCode on a VPS/container (not Vercel) - Use the Docker image
- Use the SDK client from Vercel Functions to connect to it:
import { createOpencodeClient } from '@opencode-ai/sdk';
// From Vercel Function or API route
const client = createOpencodeClient({
baseUrl: 'https://your-opencode-server.example.com',
});
####Option 3: Self-hosted OpenCode + Vercel Frontend
OpenCode has a client/server architecture (mentioned in the README):
"A client/server architecture. This for example can allow OpenCode to run on your computer, while you can drive it remotely from a mobile app."
You could:
- Run OpenCode server on a dedicated VM (AWS EC2, DigitalOcean, Railway, Fly.io, etc.)
- Build a web frontend on Vercel that uses the OpenCode SDK client to communicate with your server
###What Would Actually Work Best
Given OpenCode's requirements, the recommended setup would be:
| Component | Platform |
|---|---|
| OpenCode Server | Railway, Fly.io, or AWS/GCP/Azure container (supports Bun natively) |
| Web UI / API Gateway | Vercel (Next.js app using OpenCode SDK client) |
| Code sandbox | The OpenCode server handles this via its own tools |
The Vercel Sandbox is designed for running untrusted code snippets, not long-running development servers. OpenCode already is a sandbox for AI-generated code with its own permission system and tools.
Would you like me to dig deeper into any of these options, or explore how to set up a specific deployment architecture?
END OF POST