Skip to main content
The code-interpreter template is the standard execution target when your agent produces Python snippets and wants them run in isolation. It ships the libraries LLMs commonly importnumpy, pandas, matplotlib, plotly, scipy, scikit-learn, Pillow, SymPy, plus jupyter and ipython — so a freshly-generated snippet doesn’t stall on pip install every time. Think of it as the declaw-native backing for OpenAI’s code interpreter tool, Anthropic’s code execution tool, and similar agent primitives: feed it a string of Python, get back stdout / stderr / exit code.

What you’ll learn

  • Picking template="code-interpreter" so the common scientific imports work cold
  • Running several unrelated code snippets in the same sandbox, safely
  • Letting the agent generate code and only having the SDK execute it

Prerequisites

Code

In the example below we skip calling a real LLM and just iterate over three hand-written snippets — each one stands in for whatever your agent decides to execute next.

Expected output

A real agent loop typically does three things per tool call: generate the snippet with the model, pass it here for execution, then feed the stdout / exit code back to the model. Keep the same sandbox alive across turns so files and installed packages persist — kill it only when the task finishes.