cpuos

Integration · Agent framework

Vercel AI SDK with cpuos sandboxes

Run AI SDK tool calls in a Firecracker sandbox from Next.js or Node, with the model on any OpenAI-compatible provider.

SDK
@cpuos/sdk · pip install cpuos
Model endpoint
https://gpuos.si/v1 or any OpenAI-compatible
Status
Early access

A sandbox tool for generateText and streamText

Install
npm install ai @ai-sdk/openai-compatible zod @cpuos/sdk
TypeScript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible"import { Sandbox } from "@cpuos/sdk"import { generateText, stepCountIs, tool } from "ai"import { z } from "zod"const gpuos = createOpenAICompatible({  name: "gpuos",  baseURL: "https://gpuos.si/v1",  apiKey: process.env.GPUOS_API_KEY,})const sbx = await Sandbox.create({ template: "python", timeout: "30m" })const runPython = tool({  description: "Run a Python 3 script in an isolated sandbox. Files live in /work.",  inputSchema: z.object({ code: z.string() }),  execute: async ({ code }) => {    await sbx.files.write("/work/main.py", code)    const run = await sbx.exec("cd /work && python main.py", { timeout: "2m" })    return {      exitCode: run.exitCode,      stdout: run.stdout.slice(-4000),      stderr: run.stderr.slice(-2000),    }  },})const { text } = await generateText({  model: gpuos("qwen3-32b"),  tools: { runPython },  stopWhen: stepCountIs(8),  prompt: "Simulate 10,000 rolls of two dice and report the most common sum.",})await sbx.pause()

The examples point the model at gpuOS, which serves open models on your own GPUs at https://gpuos.si/v1 with an OpenAI-compatible API. Any other OpenAI-compatible provider works the same way: change the base URL, the key and the model name.

cpuos is in early access: @cpuos/sdk (npm) and cpuos (PyPI) ship to early-access teams first, and read the API key from CPUOS_API_KEY. The calls on this page show the current API shape.

In a Next.js route handler

Create or resume the sandbox inside the route handler, keyed by the chat id, and use streamText instead of generateText. Return result.toUIMessageStreamResponse() to stream tool calls and text into useChat. Keep both API keys in server-only environment variables.

For previews, have a tool start a dev server in the node template with sbx.exec("pnpm dev --port 3000", { background: true }) and return sbx.url(3000). The user sees the app the agent built, running in its sandbox.

Official documentation: ai-sdk.dev

Questions

How many steps should I allow?
Five to ten is typical for a code interpreter. stopWhen with stepCountIs keeps a model that keeps failing from looping forever.
Can I run this on Vercel?
Yes. The sandbox runs on cpuos, not in your function, so your route handler only makes HTTPS calls. Keep the sandbox paused between requests.
Does it work with other AI SDK providers?
Yes. The tool does not depend on the model provider. Swap gpuos('qwen3-32b') for any provider model that supports tool calling.

Related

Run Vercel AI SDK tool calls in a sandbox

cpuos is in early access: a Firecracker microVM per task, hosted in the EU or on your servers, billed per second and free while paused.

gpuOS · where models think

Need the model too? Run it on gpuOS

gpuOS serves open models on your own GPUs behind one OpenAI-compatible API. The model reasons on gpuOS, the agent acts in a cpuOS sandbox.