Execute Code
execute_codeRun code in 31 languages in an isolated sandbox and get stdout, stderr, exit code, timing, and verdict, with optional sessions, dependencies, and network blocking.
Instructions
Execute code in language in a sandbox. Use this, not
execute_code_stream/run_submit/session_run, for one program whose result
you can wait for within a 120s cap.
Returns stdout, stderr, exit_code, duration_ms, cpu_ms, peak_memory_kb, verdict (OK/TLE/MLE/OLE/RTE).
session_id: run inside a session workspace (see session_start); with a stateful session (python3/node) interpreter state persists across calls. Also reportsartifacts_created(files just created/modified) since that workspace outlives the call; a sessionless run has none. Seesession_runfor the same field plus inline content blocks.max_output_kb: the 240 KiB hard ceiling is what theanthropic/maxResultSizeCharsthis tool advertises in its_metaalready assumes — the cap leaves no headroom to raise past it without the real result exceeding that hint. A run whose real output needs more than 240 KiB belongs in a session instead: leavemax_output_kbat its default (0) withsession_idset (below), and oversized output SPILLS to a full-fidelity file readable viasession_read_filerather than truncating — see the spill paragraph further down. An EXPLICITmax_output_kb, even under the 240 KiB ceiling, is honoured as a literal cap with no spill.no_net: Linux enforces in-kernel via a seccomp-bpf filter. macOS / no-seccomp kernel: best-effort symbol shim, disclosed inunenforcedwhen that's the only guarantee that held. See SECURITY.md.compact: never dropsunenforced,output_error,artifacts_created, ordependencies— if a guarantee you asked for was not applied, or a declared install failed, a compact result still says so.dependencies: merged with a PEP 723# /// scriptblock for python3, deduped by normalized name with this argument winning; the only source for node. A block ALONE, with nodependenciesargument, is enough to trigger an install — see SECURITY.md. Installed BEFORE the sandboxed step, through the same confinedinstall_packagepath — never inside the sandbox — and refused (capability_not_requested) without installing anything whenno_net=Trueor the capability policy denies or strictly limits network. Bounded by a fixed install-time budget separate fromtimeout(120s aggregate across every dependency;codecalc.dependencies.DEFAULT_DEPENDENCY_INSTALL_BUDGET_SECONDS) and, session-less, byCODECALC_SESSION_DISK_QUOTA_MBon the run's own workdir — either one exceeded refuses the run with a stamped, coded error naming the ceiling. See thedependenciesfield on the result.
With session_id set and max_output_kb left at its default, output that
would otherwise be truncated is instead SPILLED: the inline
stdout/stderr still carry the same truncated prefix as before, and
stdout_spill/stderr_spill name a codecalc://session/{sid}/files/...
resource carrying the fuller stream (session_read_file or the resource
route reads it back) — capped at 4 MiB, ..._spill_capped: true if even
that was not enough to hold everything. Passing an EXPLICIT
max_output_kb is honoured as a literal ceiling with no spill, same as
before. Session-LESS runs (no session_id) have no workspace to spill
into and keep the old truncate-and-drop behaviour.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Source code to run in `language` | |
| stdin | No | Text piped to the program's standard input; empty means no input | |
| no_net | No | Block outbound network access for this run; best-effort on platforms without seccomp | |
| compact | No | Drop diagnostic fields (timings, workdir, platform) from the result; safety disclosures are always kept, and stderr is kept whenever the run did not succeed — dropped only on a clean successful run (ok=true, exit_code 0, verdict OK) | |
| max_cpu | No | Per-call CPU-time ceiling in seconds; 0 means no explicit limit is set | |
| timeout | No | Wall-clock seconds before the run is killed as TLE; clamped to a 120s ceiling | |
| language | Yes | Runtime to execute in, e.g. 'python3', 'node'; see list_languages for the full catalog | |
| provider | No | Execution backend id to use (see list_execution_providers); default picks automatically | |
| session_id | No | Run inside this session's workspace (from session_start) instead of a throwaway sandbox | |
| dependencies | No | Packages to install before running, e.g. ['requests==2.31.0']; merged with any PEP 723 block | |
| max_memory_mb | No | Per-call memory ceiling in MiB; 0 means no explicit limit is set | |
| max_output_kb | No | Stdout/stderr capture cap in KiB per stream; 0 uses the 64 KiB default, hard-clamped to 240 |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||