The Claude Agent SDK operates as a long-running process that executes commands, manages files, and maintains conversational state. Because the SDK runs shell commands and modifies files on behalf of the AI agent, its important to isolate it in a sandboxed container. This prevents the agent from accessing your production systems, consuming unlimited resources, or interfering with other processes.
The SDK needs specific runtime dependencies installed before it can run:
- Claude Code CLI: Executes commands and manages the development environment
- Anthropic SDK: Provides the API client for Claude Code
Vercel Sandbox provides an ephemeral space with security, customization for dependencies, resource limits and isolation.
This guide shows you how to install the Claude Agent dependencies in a Vercel Sandbox and verify they work correctly before building your agent application.
Before you begin, make sure you have:
- Vercel CLI installed on your machine. If you don't have it, install it with
npm install -g vercel - Node.js 22 or later installed locally
- A Vercel project to link your sandbox to
Create a new directory for your project and set up the required files:
The packages you installed:
@vercel/sandbox: Vercel's SDK for creating and managing sandboxesms: Helper for working with time durations- Type definitions for TypeScript support
Update your package.json to enable ES modules by adding "type": "module":
Create a tsconfig.json file for TypeScript configuration:
Link your project to Vercel:
This command connects your local project to a new or existing Vercel project, which is required for sandbox authentication.
To securely connect your Vercel deployment with your sandbox, you can use the Vercel OIDC token automatically created with a project. Pull the authentication token to your local .env.local file:
This creates a .env.local file with a VERCEL_OIDC_TOKEN that the Vercel Sandbox SDK uses for authentication. The OIDC token expires after 12 hours, so you'll need to run vercel env pull again if you're developing for extended periods.
Create a new file called claude-sandbox.ts that sets up a Vercel Sandbox, installs both Claude Code CLI and the Anthropic SDK, and verifies the installation:
- Creates a sandbox with 4 vCPUs and a 10-minute timeout
- Installs Claude Code CLI globally using
sudofor system-level access - Installs the Anthropic SDK in the working directory
- Writes a verification script to the sandbox filesystem using
writeFiles()with a Buffer - Runs the verification to confirm the SDK is properly connected
- Stops the sandbox when complete
- Uses
sandbox.sandboxIdto access the unique sandbox identifier - Checks exit codes with
!= 0for command failures - Uses
writeFiles()which accepts an array of file objects withcontentas a Buffer - Streams output to
process.stderrandprocess.stdoutfor real-time feedback
Run your script with the environment variables from .env.local:
The output should look similar to this:
To monitor your sandboxes in the Vercel dashboard:
- Navigate to your project on vercel.com
- Click the Observability tab
- Click Sandboxes in the left sidebar
- View sandbox history, command execution, and resource usage
The script automatically stops the sandbox after verification completes, but you can also manually stop sandboxes from the dashboard if needed.
Always call sandbox.stop() when your work is complete to avoid unnecessary charges:
Configure timeouts based on your installation requirements. For simple dependency installation, 5-10 minutes is usually sufficient:
Now that you've verified Claude Code CLI and Anthropic SDK work in Vercel Sandbox, you can:
- Add API Authentication: Set up your Anthropic API key to enable agent execution
- Build AI Features: Use the verified setup to build AI-powered code generation or analysis tools
- Scale to Production: Deploy your sandbox-based AI applications
You've successfully installed Claude Code CLI and the Anthropic SDK in a Vercel Sandbox and verified they're properly connected. This setup confirms that your deployment environment can support Claude's Agent SDK.
- Vercel Sandbox documentation
- Vercel SDK docs
- Hosting Claude Agent Guide
- Claude Agent SDK documentation to learn about building AI agents