# Code execution (tool)

> Canonical: https://skillalmanac.com/glossary/code-execution | Last verified: 2026-11-25 | Index status: index-eligible

Code execution, as an AI tool, lets a model write code and run it in a sandbox, an isolated environment, then use the output. Anthropic offers a code execution tool and OpenAI offers a code interpreter tool for this.

Also called: code interpreter, code execution tool, python tool AI, sandboxed code execution.

## In plain language

Language models are weak at exact arithmetic and at reading a large data file by eye. A code execution tool helps by letting the model write a short program, run it in a locked-off workspace and read the result. You upload a spreadsheet, ask for the average by region, and the model computes it instead of guessing. The workspace is separate from your computer, which limits the damage a bad program can do. The limits are practical: the model can still write wrong code, the sandbox has a fixed set of tools, and results are only as good as the file you gave it. Read the code it ran.

## Technical definition

Anthropic's code execution tool runs Bash commands and file operations in a sandboxed Linux container, with Python pre-installed. Its documentation says the container has no internet access, so only pre-installed libraries are available, and that each request runs in a new container unless you pass the earlier container ID back. OpenAI's code interpreter tool lets models write and run Python in a sandboxed environment; its documentation describes a container as a fully sandboxed virtual machine that expires if it is not used for 20 minutes. Both are vendor-run tools, not code running on your own machine.

## How it shows up when you use agents

When you attach a data file to a chat or an API request and ask for numbers, charts or a cleaned file, code execution is often the tool doing the work. The model writes code, the vendor runs it in a container and the output comes back into the conversation. Anthropic's documentation says the container has no internet access, so the model cannot download new packages while it works.

Claude Code is a different arrangement. According to the Claude Code permissions documentation, it can run commands on your own machine, and shell commands outside a built-in read-only set require approval by default. Both rely on [tool calling](/glossary/tool-calling): the model asks for an action and the host runs it. A [coding agent](/glossary/coding-agent) such as Claude Code adds your repository and your permission rules, where a vendor sandbox starts empty.

What breaks when it is misunderstood: people trust a number because "it ran code". Code can be wrong, or run on the wrong column. The safer habit is to read the code and the output, and to check the result on a small slice by hand.

Next action: upload a small CSV with a known answer, ask for the average of one column, and compare. The [Data Analysis EDA](/skills/skill-almanac/data-analysis-eda) skill is a fixed procedure for this kind of check.

## Common confusions

- **Code execution versus a coding agent.** A code execution tool runs in a vendor sandbox. A coding agent works in your project with your permissions.
- **Sandbox versus your computer.** The sandbox is separate from your machine. Per Anthropic's documentation, its container has no outbound network access.
- **Code execution versus the model guessing.** Without the tool, a model estimates numbers in text. With it, the model computes them by running a program, which can still contain errors.
- **Code interpreter versus code execution.** Vendors use different names for the same idea. OpenAI calls its tool code interpreter and Anthropic calls its tool code execution.

## Worked examples in this catalogue

### [data-analysis-eda](https://skillalmanac.com/skills/skill-almanac/data-analysis-eda)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A fixed exploratory-analysis procedure and CSV profiler that keeps findings descriptive, evidenced and caveated.

Why it exercises the concept: Profiling a CSV is a task where running code can beat estimating. The skill keeps findings tied to what was computed.

### [xlsx](https://skillalmanac.com/skills/anthropic/xlsx)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A skill that opens, edits, fixes and creates spreadsheet files and cleans messy tabular data.

Why it exercises the concept: Anthropic's documentation says its tool can analyze data, create and edit files and process uploaded files, which is the kind of work this skill describes.

### [Claude Code](https://skillalmanac.com/tools/claude-code)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The what-is-claude-code guide says Claude Code can run commands on your machine, and that shell commands outside a fixed read-only list prompt for approval by default.

Why it exercises the concept: This is the contrast case. A vendor code execution tool runs in the vendor's sandbox. Claude Code runs commands on your machine under your permission rules.

## Related terms

- [Tool calling (function calling)](https://skillalmanac.com/glossary/tool-calling.md)
- [AI agent](https://skillalmanac.com/glossary/ai-agent.md)
- [Coding agent](https://skillalmanac.com/glossary/coding-agent.md)
- [Inference](https://skillalmanac.com/glossary/inference.md)
- [Large language model (LLM)](https://skillalmanac.com/glossary/large-language-model.md)

## Sources

- [Code execution tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool), Anthropic (Claude Docs) (accessed 2026-11-24)
- [Code Interpreter](https://developers.openai.com/api/docs/guides/tools-code-interpreter), OpenAI (API Docs) (accessed 2026-11-24)
- [Configure permissions](https://code.claude.com/docs/en/permissions), Anthropic (Claude Code Docs) (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
