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

  1. You send code (and optionally files, packages and input) to an API.
  2. The service starts or reuses an isolated environment — a container, microVM or WebAssembly runtime.
  3. The code runs with limits on time, memory, CPU and network.
  4. You get back stdout, stderr, return values and any output files.

What to look for

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 APIDeployed function
Code per callNew each timeFixed until you publish
ReviewHard — it changes constantlyEasy — a diff per version
StartupOften a fresh sandboxWarm, versioned build
Good forInterpreters, analysis, playgroundsAPIs, 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.

Related