@ai-sdk/code-mode has 38,862 recorded weekly downloads on npm, a decrease of 3.2% over the past 30 days, ranking #641 of 2,322 tracked listings.
About @ai-sdk/code-mode
AI SDK Code Mode
@ai-sdk/code-mode lets models write JavaScript or TypeScript that calls your
AI SDK tools. The code runs in an isolated QuickJS sandbox and returns a
JSON-serializable value.
Use code mode when a model needs to call several tools, transform their results, or run them concurrently. Only the tools you provide are available to the generated code.
Installation
pnpm add ai @ai-sdk/code-mode
This package runs on the server and requires Node.js 22.13 or newer.
Usage
import {
DIRECT_TOOL_CALL,
experimental_codeModeTool as codeModeTool,
} from '@ai-sdk/code-mode';
import { generateText, isStepCount, tool } from 'ai';
import { z } from 'zod';
const getInventory = tool({
description: 'Get available inventory for a product.',
inputSchema: z.object({ productId: z.string() }),
outputSchema: z.object({
productId: z.string(),
availableUnits: z.number(),
}),
execute: async ({ productId }) => ({
productId,
availableUnits: 42,
}),
});
const getDemand = tool({
description: 'Get requested units for a product.',
inputSchema: z.object({ productId: z.string() }),
outputSchema: z.object({
productId: z.string(),
requestedUnits: z.number(),
}),
execute: async ({ productId }) => ({
productId,
requestedUnits: 31,
}),
});
const tools = {
code_mode: codeModeTool({
executionPolicy: {
timeoutMs: 30_000,
},
}),
getInventory,
getDemand,
} as const;
const result = await generateText({
model,
tools,
experimental_toolCallers: {
getInventory: ['code_mode', DIRECT_TOOL_CALL],
getDemand: ['code_mode'],
},
stopWhen: isStepCount(10),
prompt: 'Compare inventory and demand for product sku_123.',
});
The model can then generate code like:
const [inventory, demand] = await Promise.all([
tools.getInventory({ productId: 'sku_123' }),
tools.getDemand({ productId: 'sku_123' }),
]);
return {
sufficient: inventory.availableUnits >= demand.requestedUnits,
remaining: inventory.availableUnits - demand.requestedUnits,
};
Direct Execution
Use experimental_runCodeMode to run code directly:
import { experimental_runCodeMode as runCodeMode } from '@ai-sdk/code-mode';
const result = await runCodeMode({
js: 'return await tools.getInventory({ productId: "sku_123" });',
tools: { getInventory },
});
Description from the npm listing.
- ai
- ai-sdk
- agents
- code-mode
- quickjs
- sandbox
- tools
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (544)Similar npm AI SDKs plugins
All 20 @ai-sdk/code-mode alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/@ai-sdk/code-mode. First seen Oct 16, 2026; last successful collection Oct 20, 2026. See the methodology.