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 add ai-sdk-tool-code-execution
# Add to your .env file
VERCEL_OIDC_TOKEN=your_api_key_here

Usage

import { generateText, isStepCount } from 'ai';
import { executeCode } from 'ai-sdk-tool-code-execution';

const { text } = await generateText({
  model: 'openai/gpt-5.1-codex',
  prompt: 'What is 5 + 5 minus 84 cubed?',
  tools: {
    executeCode: executeCode(),
  },
  stopWhen: isStepCount(5),
});

console.log(text);