code-executionsandboxmcpcode-mode

Transform MCP tools and AI SDK tools into code, write it to a Vercel sandbox file system and have the agent import the tools, write code, and execute it.

Installation

pnpm
npm
yarn
bun
pnpm install ctx-zip
# Add to your .env file
VERCEL_OIDC_TOKEN=your_api_key_here

Usage

import { gateway, generateText, stepCountIs } from 'ai';
import { createVercelSandboxCodeMode, SANDBOX_SYSTEM_PROMPT } from 'ctx-zip';
const { tools } = await createVercelSandboxCodeMode({
servers: [
{
name: 'vercel',
url: 'https://mcp.vercel.com',
useSSE: false,
headers: {
Authorization: `Bearer ${process.env.VERCEL_API_KEY}`,
},
},
],
standardTools: {
weather: weatherTool,
},
});
const { text } = await generateText({
model: gateway('openai/gpt-4.1-mini'),
tools,
stopWhen: stepCountIs(20),
system: SANDBOX_SYSTEM_PROMPT,
messages: [
{
role: 'user',
content: 'What tools are available from the Vercel MCP server?',
},
],
});
console.log(text);