Skip to main content

Code Mode Overview

@interopio/code-mode is a TypeScript package that lets an LLM orchestrate registered tools through JavaScript executed in an isolated QuickJS WebAssembly sandbox. The model receives three stable meta-tools instead of every available tool definition.

Installation​

npm install @interopio/code-mode

Use the browser entry point in web applications and the Node.js entry point in server applications:

import { IoCodeModeFactory } from "@interopio/code-mode/browser";
import { IoCodeModeFactory } from "@interopio/code-mode/node";

The package includes the QuickJS WebAssembly file at @interopio/code-mode/dist/emscripten-module.wasm. The browser entry point needs a browser-served URL for wasmLocation; the Node.js entry point needs a filesystem path.

Copy the package-provided file into any static-assets or deployment directory you control, then use its URL or path. Browser hosts can also use a version-pinned CDN URL:

wasmLocation: "https://unpkg.com/@interopio/code-mode@0.0.2/dist/emscripten-module.wasm";

Pin the package version when using a CDN. Self-host the WASM file when your deployment requires controlled availability or a restrictive content security policy.

Main API​

IoCodeModeFactory(config) returns a root API that owns the configured sandbox. Call createSession() for a tool registry and obtain its model-facing tools with getLlmTools().

const codeMode = await IoCodeModeFactory({
wasmLocation: "/quickjs/emscripten-module.wasm",
});

const session = codeMode.createSession();
session.setTools(hostTools);

const systemInstruction = codeMode.getSystemInstruction();
const toolsForModel = session.getLlmTools();

Pass systemInstruction and toolsForModel to the host's model integration. The returned tool set contains getTools, getToolDefinition, and executeCode.

Each returned tool has _meta: { "io.interop/code-mode": true }. Use the exported CodeModeToolMetaKey to recognize Code Mode tools when combining them with other tools. getLlmTools() captures the session's current registry; call it again after setTools() to expose updated tools to future runs.

The root API also provides getSession(id) to retrieve a stored session and removeSession(id) to unregister it. Remove sessions when their owner goes away: removal aborts in-flight execution for that session without affecting other sessions or the shared sandbox.