> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/maiagent-user-guide/en/build/agent/code-interpreter.md).

# Code Interpreter (Code Execution)

Code execution tool (Code Interpreter): enables AI assistants to write and run Python code in a secure sandbox—for calculations, data analysis, uploaded-file processing, chart creation, and generating

## What Is This? <a href="#what-is-this" id="what-is-this"></a>

Code Interpreter lets an Agent execute Python code in a **secure sandbox environment**, completing tasks programmatically.

With Code Interpreter enabled, the Agent can do more than just reply with text — it can write code to perform calculations, process files you upload, generate Word/PowerPoint/Excel documents, and return the results for you to download.

## How Is It Different from Tools? <a href="#code-interpreter-vs-tool" id="code-interpreter-vs-tool"></a>

|                       | Tools                                                  | Code Interpreter                                        |
| --------------------- | ------------------------------------------------------ | ------------------------------------------------------- |
| **Nature**            | Calls pre-defined external APIs                        | Writes and executes Python on the fly in a sandbox      |
| **Flexibility**       | Limited to what the API provides                       | Anything Python can do                                  |
| **Typical use cases** | Send emails, query CRM, integrate third-party services | Computation, data processing, file generation, charting |

**Quick rule of thumb**: Need to call an external API → Tools; need to compute, process files, or generate documents → Code Interpreter.

## What Can It Do? <a href="#what-it-can-do" id="what-it-can-do"></a>

* **Data analysis & computation**: CSV/Excel calculations, statistics, pivot tables, data cleaning
* **Chart creation**: Turn data into line charts, bar charts, pie charts, and more
* **Document generation**: Produce Word, PowerPoint, Excel, and PDF files for download
* **File processing**: Parse PDFs, convert formats, batch-process uploaded files

## Sandbox Environment <a href="#sandbox-environment" id="sandbox-environment"></a>

* The execution environment is a **secure sandbox**, isolated from production systems — it won't affect any other data
* Supports standard Python along with common data and document processing packages
* Files generated by the Agent appear in the **Output** panel within the chat interface and can be downloaded directly

## When to Use <a href="#when-to-use" id="when-to-use"></a>

* Finance/sales teams ask the Agent to organize Excel files and produce weekly reports
* HR/admin teams ask the Agent to turn survey results into charts and generate PowerPoint presentations
* Legal/contract teams ask the Agent to extract key fields from PDFs and output Word summaries
* Any conversation scenario that requires ad-hoc computation or on-the-fly file generation

## What Do I Need to Do? <a href="#what-do-i-need-to-do" id="what-do-i-need-to-do"></a>

1. **Go to Agent settings** — Open the settings page of the AI Assistant you want to enable it for
2. **Enable Code Interpreter** — Turn it on in the tools or advanced capabilities section
3. **Test** — Ask the Agent to perform a task that requires computation or file generation in a conversation, and verify that the Output panel allows normal downloads


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maiagent.ai/maiagent-user-guide/en/build/agent/code-interpreter.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
