Skip to main content
OpenAI Code Interpreter gives an OpenAI agent a sandboxed Python environment for exact math, data slicing, and analysis.

What it does

When enabled, the agent can call OpenAI’s hosted python tool to write and run Python in an ephemeral container. Use it when you need exact results that language models alone cannot guarantee — for example splitting spreadsheet rows into precise batches, computing statistics, or transforming tabular data. Important: Prefer File Tools (write_file) for deliverable PDF/DOCX/XLSX/CSV when the model can print text content. If the model still saves files inside the sandbox and cites them, Fetch Hive automatically downloads those container files and stores them as workspace assets (rewriting sandbox: links to real download URLs).

Requirements

  • Agent provider must be OpenAI.
  • The tool is not enabled by default — add it from the tool picker.

Adding the tool to an agent

  1. Open an agent in the editor.
  2. Click the button with the tooltip Add MCP Tool or Sub Agent.
  3. In MCP Tools, click OpenAI Code Interpreter.
There are no per-tool settings in v1. Containers use OpenAI’s default 1 GB memory tier.

How it works with File Tools

Typical flow for spreadsheet slicing:
  1. Document attachments (csv/xlsx/pdf/docx/txt/md) on the turn are auto-mounted into the Code Interpreter sandbox at /mnt/data/<name> for both hosted and BYOK OpenAI keys (up to 10 files, 50 MB each). The sandbox has no internet access — the agent should read mounted files directly, not fetch URLs.
  2. Code Interpreter runs Python to slice or transform the data and prints CSV/JSON.
  3. The agent calls write_file with that text to create downloadable XLSX/CSV assets.
If the model instead writes files into /mnt/data and links them with sandbox: URLs, Fetch Hive captures those container files via OpenAI’s Containers API and promotes them to real workspace assets (same storage path as write_file). Prefer write_file when possible. Mounted input files are re-uploaded to OpenAI each turn (1-hour expiry) and do not persist across turns.

Limitations (v1)

  • OpenAI only — Anthropic and xAI code-execution tools are not wired yet.
  • No multi-turn Python state — each agent turn starts a fresh container; variables from a previous turn do not persist.
  • Fixed 1 GB memory — higher OpenAI memory tiers are not exposed yet.
  • Attachment mount caps — at most 10 document attachments / 50 MB each are mounted per turn; larger or excess files are skipped (File Tools read_file remains available).
  • Each Code Interpreter call counts as 1 task credit (same pattern as GPT Search). Container-minute spend is tracked only as estimated operator metadata (estimated: true) on the completion — not a separate user-facing USD line item. On hosted keys, OpenAI container minutes are absorbed by Fetch Hive. Mounting attachments via the Files API does not add extra task credits.

Use cases

  • Exact row slicing (rows 1–50, 51–100, …) before exporting XLSX batches.
  • Numerical / statistical calculations that must be precise.
  • Parsing or reshaping tabular data before writing a file.

Notes