How it works
The model writes a short program and sends it to the tool. The tool runs the program in an isolated environment. It returns the output to the model, for example text, a chart or a file.
Anthropic's code execution tool returns three parts: stdout, stderr and a return code. A return code of 0 means success.
State between calls
Some environments keep state between calls. An OpenAI Code Interpreter container keeps its files and Python objects while it is active. It expires after 20 minutes without activity, and its Python objects are then lost.
A Jupyter kernel runs each piece of code in one namespace for the user's variables. A later call can use a variable that an earlier call set.
Anthropic's code execution tool starts a new container for each request. It reuses an earlier container only when you pass its ID back.
Why it runs in a sandbox
The model chooses the code. The environment must limit what that code can reach. A sandbox does that. Anthropic describes its code execution tool as running in a sandboxed container.
What to check on a provider
- Whether files and variables stay between calls, and for how long.
- Which outputs come back: text, errors, charts and files.
- The idle timeout of the environment.