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.
pnpm install ai-sdk-tool-code-execution# Add to your .env fileVERCEL_OIDC_TOKEN=your_api_key_hereimport { 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);