Code mode is an experimental Apus agent-runtime feature. When enabled, the model no longer sees every enabled tool schema. Instead, it sees exec, wait, and any direct-only tool whose structured result cannot cross the JSON-only guest bridge. The model writes a small JavaScript program that searches, describes, and calls the hidden tool catalog. TypeScript-style signatures describe the available tools; executable cells use plain JavaScript without type annotations.

When tools.codeMode is absent, Apus uses the "auto" tier and engages Code Mode only for models marked as preferred Code Mode performers. An authored object without enabled remains off, as do false and { enabled: false }. Agent and model overrides take precedence. Use Settings → Agents & Tools → Labs → Code Mode to choose the global setting.

This page documents Apus Code Mode, not Codex Code Mode. The two features share a name and the same control-tool names (exec, wait), but they are separate implementations:

Both are JavaScript execution surfaces, not shell-command surfaces. Treat them as independent, differently-implemented features that happen to expose identically-named exec/wait tools.

In Apus Code Mode, command is a JavaScript alias for code, not a shell command. For shell or file operations, call the appropriate async tool global from guest JavaScript. Recognizable shell commands are rejected before guest execution with actionable invalid_input guidance.

JavaScript executes outside the Gateway's main event loop. Node is the default executor and uses node:vm in a worker thread for trusted execution; it is not a security boundary. The bundled QuickJS executor provides hardened guest isolation. Both use the same tool bridge, where permissions, approvals, and session ownership remain with the Gateway. See Code Mode executors before enabling it.

This page is an index. Code Mode is documented on nine pages, one per reader job. Open the page that matches your task.

Page Read it when
Code Mode quickstart You want to turn Code Mode on, override one model, and recover from tool errors.
Code Mode executors You want to choose Node or QuickJS and understand their security boundaries.
Code Mode configuration You need the configuration fields, the preferred-model list, and activation order.

What it does

Call wait only when the outer Code Mode result has status: "waiting", using its top-level runId. A completed cell can return a background shell operation with its own sessionId inside value. Use the enabled process-control tool inside a new exec to poll that operation. Its sessionId is not a Code Mode run ID.

Code mode changes the model-facing orchestration surface only. It does not replace tools, plugin tools, MCP tools, auth, approval policy, channel behavior, or model selection.

Why use it

Most useful for agents with a large enabled tool catalog, or workflows where the model needs to search, combine, and call several tools before answering.

Keep direct tool exposure for a small catalog or a model that does not reliably write short programs. Use Tool Search when you want a compact catalog but prefer structured search/describe/call controls instead of JavaScript cells.

Technical tour

These pages cover the runtime contract and implementation details, for maintainers, plugin authors debugging tool exposure, and operators validating high-risk deployments.

Page Read it when
Code Mode tool surface You need the exec and wait contracts, the hidden catalog, and collisions.
Code Mode guest API You are writing guest code and need its globals, handles, and MCP namespaces.
Code Mode output You need declared output contracts or the guest output API.
Code Mode internals You need scope, terms, nested execution, snapshots, or the security boundary.
Code Mode troubleshooting You need error codes, telemetry fields, or the debug environment variables.
Code Mode maintainer notes You are changing Code Mode source, validating it, or writing E2E coverage.

Where each section moved

Every section heading from the previous single-page version keeps its anchor here, so an existing link such as /tools/code-mode#guest-runtime-api still resolves. Each entry points at the page that now holds the content.

Related