Code interpreter (experimental)
Experimental
The code interpreter is experimental. It depends on
langchain-quickjs (bundled inside deepagents[quickjs]).
Install the optional extra: uv pip install "abt-core[quickjs]".
Enable it for agents that need to run sandboxed JavaScript — data transforms, formula evaluation,
algorithmic reasoning — without leaving the Python process.
What it does
Declare a - code_interpreter: entry in the middleware: list to add CodeInterpreterMiddleware
to the agent's middleware stack. The middleware exposes a single tool (default name: eval) that
executes JavaScript inside a QuickJS sandbox:
- Isolated VM — code runs in a separate QuickJS instance; it cannot access the filesystem, network, or Python heap unless explicitly wired through Programmatic Tool Calls (PTCs).
- Configurable limits — memory, wall-clock timeout, and result size are all capped per invocation and configurable per project/agent.
- REPL persistence — variables defined in one turn are available in the next (
mode: thread).
The code interpreter improves computational accuracy by letting the model delegate exact arithmetic and data transforms to a deterministic runtime.
Install
uv pip install "abt-core[quickjs]"
Enable globally (abt.yaml)
config:
middleware:
- code_interpreter: {}
All other fields use sensible defaults (see Configuration reference below). A minimal production setup might also tighten the limits:
config:
middleware:
- code_interpreter:
timeout: 10.0
memory_limit: 134217728 # 128 MiB
max_result_chars: 8000
Per-agent overrides
Override the project's code_interpreter middleware entry by name. In the agent's frontmatter, add:
middleware:
- code_interpreter:
timeout: 3.0
tool_name: run_js
capture_console: false
mode: thread
Precedence follows the middleware cascade: agent middleware: > abt.yaml scoped tiers (agents.<name>.config) > config.middleware.
Configuration reference
All fields are optional; the default values match the upstream CodeInterpreterMiddleware defaults.
| Field | Type | Default | Description |
|---|---|---|---|
enabled |
bool | — | Not a setting. The cascade reads it, so enabled: false turns the middleware off for an agent or scope. |
memory_limit |
int | 67108864 |
QuickJS heap limit in bytes (default 64 MiB). |
timeout |
float | 5.0 |
Wall-clock seconds per eval call. |
max_ptc_calls |
int | null | 256 |
Max programmatic tool calls per eval call. null or 0 = unlimited. |
tool_name |
str | "eval" |
Name the agent sees for the code-execution tool. |
max_result_chars |
int | 4000 |
Truncate result output to this many characters. |
capture_console |
bool | true |
Include console.log output in the result. |
mode |
str | "thread" |
REPL state persistence: thread (across calls and turns), turn (within a turn only), or call (fresh REPL per eval). Any other value fails config validation. |
max_snapshot_bytes |
int | null | null |
Maximum snapshot size in bytes. null or 0 = upstream default (equals memory_limit). |
snapshot_signing_key |
str | null | null |
HMAC-SHA256 key to sign/verify persisted mode: thread snapshots. Resolve it from {{ env_var('NAME') }} — never a literal secret in committed YAML. See Snapshot integrity below. |
ptc |
bool | list[str] | false |
Expose the agent's own tools as tools.<name>() inside the JS REPL (Programmatic Tool Calling). true exposes the whole toolset; a list exposes a named subset. See Programmatic tool calling (PTC) below. |
subagents |
bool | true |
Expose a top-level task(...) JS global for dynamic subagent dispatch (loops/Promise.all over the agent's configured subagents). See Dynamic subagent dispatch below. |
Snapshot integrity (mode: thread)
When mode: "thread" persists REPL snapshots via the checkpointer, anyone who can write to
that checkpointer's storage can tamper with a persisted snapshot — e.g. a shared DynamoDB
table other services or support tooling can also reach. Set snapshot_signing_key to
HMAC-sign snapshots on write and verify them on restore; a snapshot with a missing or invalid
signature is discarded (the thread starts a fresh REPL) rather than restored.
Reference the key by name, never by literal value in committed config:
middleware:
- code_interpreter:
mode: thread
snapshot_signing_key: "{{ env_var('QUICKJS_SNAPSHOT_HMAC_KEY') }}"
Set QUICKJS_SNAPSHOT_HMAC_KEY to a high-entropy secret (openssl rand -hex 32) in
profiles.yaml's env: block (gitignored) or the deployment's own secret store. Use the same
key across every process that shares a thread; rotate it by starting fresh threads.
Programmatic tool calling (PTC)
Lets JS inside eval call the agent's own tools directly (tools.<name>()), instead of
round-tripping to the model per call:
config:
middleware:
- code_interpreter:
ptc: true # every bound tool, or:
# ptc: ["search", "fetch_page"] # a named subset (entries match like tools: entries)
Unknown names warn and are skipped, not a hard failure. max_ptc_calls caps tools.* calls per eval call, so one turn can make max_ptc_calls times as many calls as it makes eval calls.
@isolated_tool tools work through ptc too; each tools.<name>() call runs in its own worker process.
A tool with a tool_call_limit entry is not exposed through ptc (abt logs a warning), whether ptc lists it or is true. The agent still calls it as a regular tool, where the limit applies.
A tool that needs a human confirmation (confirmation_required: true, see Tool confirmation) is not exposed through ptc either (abt logs a warning), whether ptc lists it or is true, and even when it sets on_missing_gate: approve. A tools.<name>() call runs inside an already-approved eval invocation and skips the approval gate, so exposing the tool would let one approved eval run it with no human decision. The agent still calls it as a regular tool, where the gate applies.
tools.<name>() calls skip the agent's regular tool-call path, so middleware that wraps tool calls does not see them:
| Middleware | On a tools.<name>() call |
|---|---|
tool_call_limit |
Not applied, so a limited tool is kept out of ptc (above). |
tool_result_cache |
Not applied. Repeated identical calls run again. |
tool_retry |
Not applied. A failed call is not retried. |
approvals: |
Not applied, so a gated tool is kept out of ptc (above). |
Dynamic subagent dispatch (task())
On top of eval, upstream also exposes a task(...) JS global (enabled by default) that lets the
JS code dispatch the agent's own configured subagents from inside a loop or Promise.all — no
extra round trip to the model per dispatch.
Like PTC, a task() call runs inside an already-approved eval invocation: it does not
trigger a parent-level approval gate per dispatch, since from the model's perspective
only one tool call (eval) was made. If your subagents require per-call approval, disable dynamic
dispatch:
config:
middleware:
- code_interpreter:
subagents: false
Middleware ordering
Middleware runs in the order you declare it in the middleware: list, except where a middleware has an
ordering constraint. code_interpreter has none, so place it wherever
makes sense. If you also use compaction or collapse, declaring those
first keeps the REPL tool's own output subject to the same trimming as any other tool call:
config:
middleware:
- compaction: {}
- code_interpreter: {}
Logs
- If
langchain-quickjsis configured but not installed, abt logs a WARNING naming the missing package and how to install it.
Further reading
- Upstream API: langchain-quickjs README.
- Related: Context compaction (experimental).