code-executionsandbox

Execute Python code in a sandboxed environment using Vercel Sandbox. Run calculations, data processing, and other computational tasks safely in an isolated environment with Python 3.13.

Installation

pnpm
npm
yarn
bun
pnpm install ai-sdk-tool-code-execution
# Add to your .env file
VERCEL_OIDC_TOKEN=your_api_key_here

Usage

import { gateway, generateText, stepCountIs } from 'ai';
import { executeCode } from 'ai-sdk-tool-code-execution';
const { text } = await generateText({
model: gateway('openai/gpt-5.1-codex'),
prompt: 'What is 5 + 5 minus 84 cubed?',
tools: {
executeCode: executeCode(),
},
stopWhen: stepCountIs(5),
});
console.log(text);