AI Inference Benchmark: Keln vs Fireworks, Baseten, Modal, DeepInfra & Z.ai
ProductCode execution3 min read

Code execution for open models: Run Python and shell commands in any response

Let any Keln chat model run Python and shell commands while it answers. Code runs in an isolated Linux sandbox, and the model uses the results in its response.

Models can write code, but without executing it, they can only predict the results. Code execution lets them calculate exact answers, test their code, and catch errors before responding.

We've added code execution to all chat models on Keln. Models can now run Python and shell commands, read the output, and use the results in their answers.

Keln code execution: a model sends code to a small blue sandbox and gets the output back

What can you do with code execution?

Code execution lets a model run code on Keln's servers. The model decides when to use it and can run multiple commands before returning an answer.

Some examples:

  • Calculations and statistics: Calculate exact results from data in your prompt.
  • Data processing: Parse and transform CSV, JSON, and plain text.
  • Code testing: Run code and check whether it produces the expected output.
  • Math: Solve equations and verify results using SymPy.

How code execution works

When a model needs to run code, Keln starts an isolated Linux sandbox. Each response gets its own sandbox with:

  • Ubuntu, 2 vCPUs, and 2 GiB of memory.
  • Python 3.12 and Node.js 24.
  • Preinstalled libraries including pandas, NumPy, SciPy, scikit-learn, SymPy, and matplotlib.
  • Libraries for working with Excel, Word, PowerPoint, and PDF files.

The model can run multiple commands and use files created by earlier commands in the same response.

Once the response finishes, Keln deletes the sandbox and its files.

Code execution sandboxes have no network access. The model works with data provided in the request.

Use code execution with OpenAI and Anthropic SDKs

OpenAI SDK and Anthropic SDK connected to Keln code execution

Code execution works with every chat model on Keln, using each API's own tool:

  • Responses API: code_interpreter for Python and shell for shell commands.
  • Anthropic Messages API: code_execution server tool.
  • Chat Completions API: code_interpreter in the Responses format.

The Responses and Anthropic-compatible APIs return commands and their output in their native formats. Chat Completions can return them on request.

You can also use code execution alongside your own function tools in the same request.

Get your API key

Code execution vs. sandboxes

Keln offers both code execution and sandboxes for AI agents.

Code execution is for running code while a model generates an answer. Each response gets a temporary sandbox that's deleted when the response ends.

Sandboxes are for applications and agents that need to control a Linux machine directly. They support network access, persistent files, and running servers.

Code execution pricing

Code execution is billed per second of sandbox time, from the first command until the response ends, plus the model's token usage.

If the model doesn't run code, there's no sandbox charge.

You use the same Keln API key and prepaid balance for models and code execution. See the pricing documentation for current rates.

Code execution privacy

Keln doesn't store executed code or its output. Each response that runs code gets its own isolated virtual machine, which Keln deletes with its files when the response ends.

Get started with code execution

See the code execution documentation for examples using each API, available settings, and response formats.

Code executionCode interpreterOpen modelsAPI

Try code execution

We've added code execution to all chat models on Keln.