experimental-ai-sdk-code-mode weekly downloads statistics
By vercel-labs (8 listings) · npm · AI SDKs
QuickJS-backed code mode tool for AI SDK
experimental-ai-sdk-code-mode has 11,802 recorded weekly downloads on npm, a decrease of 50.6% over the past 30 days, ranking #1212 of 3,247 tracked listings.
About experimental-ai-sdk-code-mode
AI SDK Code Mode
experimental-ai-sdk-code-mode provides an AI SDK tool that runs JavaScript or
type-stripped TypeScript in an isolated QuickJS WASM sandbox. It is meant for
agents that need to call several tools, combine their results, run independent
tool calls concurrently, or do structured JSON transformations in one step.
Installation
pnpm add ai experimental-ai-sdk-code-mode
The runtime uses Node.js worker threads and is intended for server-side AI SDK tools, not browser execution.
ai is a peer dependency. The package supports AI SDK 6 stable and AI SDK 7
beta:
pnpm add ai@^6 experimental-ai-sdk-code-mode
pnpm add ai@beta experimental-ai-sdk-code-mode
Quick Start
import { generateText, tool } from "ai";
import { z } from "zod";
import { createCodeModeTool } from "experimental-ai-sdk-code-mode";
const search = tool({
description: "Search indexed documents.",
inputSchema: z.object({
query: z.string(),
limit: z.number().int().optional(),
}),
outputSchema: z.object({
results: z.array(
z.object({
id: z.string(),
title: z.string(),
}),
),
}),
execute: async ({ query, limit }) => {
return { results: await searchDocuments(query, limit) };
},
});
const readDocument = tool({
description: "Read a document by id.",
inputSchema: z.object({
id: z.string(),
}),
outputSchema: z.object({
id: z.string(),
title: z.string(),
body: z.string(),
}),
execute: async ({ id }) => {
return await readDocumentById(id);
},
});
const codeMode = createCodeModeTool(
{
search,
readDocument,
},
{
executionPolicy: {
timeoutMs: 30_000,
memoryLimitBytes: 64 * 1024 * 1024,
},
},
);
const result = await generateText({
model,
tools: { codeMode },
prompt: "Search for the latest internal QuickJS notes and summarize them.",
});
What The Model Sees
createCodeModeTool(tools) generates the code-mode tool description from the
provided AI SDK tools. The description includes:
- sandbox rules
- whether
fetchis available, plus the configured fetch policy when present - TypeScript call signatures for every provided tool, including return types
when the tool provides an AI SDK
outputSchema - examples for calling tools and returning the final value
For example, if you pass search and readDocument, the model sees guidance
like this in the code-mode tool description:
declare const tools: {
/** Search indexed documents. */
search: (input: {
query: string;
limit?: number;
}) => Promise<{
results: Array<{
id: string;
title: string;
}>;
}>;
/** Read a document by id. */
readDocument: (input: {
id: string;
}) => Promise<{
id: string;
title: string;
body: string;
}>;
};
Inside code mode, calls look like normal async JavaScript:
const { results } = await tools.search({ query: "QuickJS", limit: 5 });
const documents = await Promise.all(
results.map((item) => tools.readDocument({ id: item.id })),
);
return {
count: documents.length,
titles: documents.map((doc) => doc.title),
};
JSON.parse and JSON.stringify are available in the sandbox. Returned values
and tool inputs/outputs must be JSON-serializable.
API
createCodeModeTool(tools, options?)
Returns an AI SDK tool() whose input schema is:
{
js: string;
}
The js string is wrapped in an async function, so top-level await and
return are supported:
const first = await tools.search({ query: "sandbox" });
return { first };
The package also exports the lower-level runner:
import { runCodeMode } from "experimental-ai-sdk-code-mode";
const output = await runCodeMode({
js: "return await tools.add({ a: 1, b: 2 });",
tools: {
add: tool({
inputSchema: z.object({ a: z.number(), b: z.number() }),
execute: async ({ a, b }) => ({ sum: a + b }),
}),
},
});
Options
interface CodeModeOptions {
executionPolicy?: {
timeoutMs?: number;
memoryLimitBytes?: number;
maxStackSizeBytes?: number;
maxResultBytes?: number;
maxSourceBytes?: number;
maxToolInputBytes?: number;
maxToolOutputBytes?: number;
maxBridgeRequests?: number;
maxInFlightBridgeRequests?: number;
};
fetchPolicy?: false | {
fetch?: typeof globalThis.fetch;
allowedOrigins?: string[];
allowedUrlPrefixes?: string[];
allowedMethods?: string[];
maxResponseBytes?: number;
allowRedirects?: boolean;
maxRedirects?: number;
};
approval?: {
mode?: "callback" | "interrupt";
onApprovalRequired?: (request: {
toolName: string;
input: unknown;
toolCallId: string;
}) =>
| "approved"
| "denied"
| { approved: boolean; reason?: string }
| Promise<"approved" | "denied" | { approved: boolean; reason?: string }>;
};
lifecycle?: {
onNestedToolCall?: (event: CodeModeNestedToolCallEvent) => void | Promise<void>;
onNestedToolResult?: (event: CodeModeNestedToolResultEvent) => void | Promise<void>;
onFetchRequest?: (event: CodeModeFetchRequestEvent) => void | Promise<void>;
onFetchResult?: (event: CodeModeFetchResultEvent) => void | Promise<void>;
onInterrupt?: (event: CodeModeInterruptEvent) => void | Promise<void>;
onTrace?: (trace: CodeModeTrace) => void | Promise<void>;
onHookError?: (
error: unknown,
event: CodeModeLifecycleHookErrorEvent,
) => void | Promise<void>;
};
telemetry?: {
isEnabled?: boolean;
tracer?: unknown;
recordInputs?: boolean;
recordOutputs?: boolean;
functionId?: string;
metadata?: Record<string, unknown>;
};
modelOutput?: {
includeNestedToolSummary?: boolean;
includeNestedToolOutputs?: boolean;
includeFetchSummary?: boolean;
maxSummaryEntries?: number;
};
}
Defaults:…
Description from the npm listing.
- 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 (170)Similar npm AI SDKs plugins
All 20 experimental-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/experimental-ai-sdk-code-mode. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.