Resources / Code execution
Code execution APIs: running untrusted Python and JavaScript on demand
How code execution APIs work, what to look for (isolation, limits, packages, latency) and when to deploy code as an endpoint instead.
A code execution API takes source code, runs it somewhere safe, and returns the output. AI products use them as a "code interpreter"; education sites use them to run student code; automation tools use them for user-defined steps.
How they work
- You send code (and optionally files, packages and input) to an API.
- The service starts or reuses an isolated environment — a container, microVM or WebAssembly runtime.
- The code runs with limits on time, memory, CPU and network.
- You get back stdout, stderr, return values and any output files.
What to look for
- Isolation. How is one execution separated from another, and from the host? Containers alone are weaker than microVMs or gVisor-style sandboxes for hostile code. See sandboxing for AI code.
- Limits. Timeouts, memory caps, output size, process counts. They should be enforced by the platform, not by the code.
- Network policy. Can you block egress entirely, or allow only some hosts?
- Packages. Can code import third-party libraries, and are they pre-installed or fetched per run (slow)?
- Latency. Cold starts range from milliseconds (WebAssembly, isolates) to seconds (full VMs).
- State. Is each run fresh, or can a session keep files and variables between calls?
- Cost model. Per execution, per second, or per session.
Ad-hoc execution vs deployed functions
Code execution APIs are ideal when the code changes on every call — a data question, a user's snippet. When the same code runs again and again — an API, a webhook, a nightly job — it's cheaper, faster and safer to deploy it once as a function:
| Execution API | Deployed function | |
|---|---|---|
| Code per call | New each time | Fixed until you publish |
| Review | Hard — it changes constantly | Easy — a diff per version |
| Startup | Often a fresh sandbox | Warm, versioned build |
| Good for | Interpreters, analysis, playgrounds | APIs, webhooks, tools for agents |
Running code on Wisp
Wisp is the deployed side: describe what the code should do, and Wisp writes it in JavaScript or Python, installs the packages it imports, and serves it at a URL — isolated per project, with time and memory limits, encrypted secrets, logs, and automatic scaling. Agents can then call it as a tool over MCP instead of generating the same code again on every request.
Build it with Wisp — describe an API, get it live.