> 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/agent-builder/code-interpreter.md).

# Code Interpreter

## 這是什麼？ <a href="#what-is-this" id="what-is-this"></a>

Code Interpreter 讓 Agent 能在**安全沙盒環境**中執行 Python 程式碼，用程式的方式完成任務。

啟用 Code Interpreter 後，Agent 不再只能用文字回答，它還能：自己寫程式做計算、處理你上傳的檔案、產出 Word／PowerPoint／Excel 等檔案，並把結果回傳給你下載。

## 跟工具有什麼不同？ <a href="#code-interpreter-vs-tool" id="code-interpreter-vs-tool"></a>

|            | 工具              | Code Interpreter   |
| ---------- | --------------- | ------------------ |
| **本質**     | 呼叫已定義好的外部 API   | 在沙盒中即時撰寫並執行 Python |
| **彈性**     | 受限於 API 提供的能力   | 任何 Python 能做的都行    |
| **典型使用情境** | 寄信、查 CRM、串第三方服務 | 計算、資料處理、產生檔案、繪圖    |

**簡單判斷**：要打外部 API → 工具；要算東西、處理檔案、產出文件 → Code Interpreter。

## 能做什麼？ <a href="#what-it-can-do" id="what-it-can-do"></a>

* **資料分析與計算**：CSV／Excel 試算、統計、樞紐、清洗
* **圖表繪製**：把資料畫成折線、長條、圓餅等圖表
* **文件生成**：產出 Word、PowerPoint、Excel、PDF 給你下載
* **檔案處理**：解析 PDF、轉換格式、批次處理上傳檔案

## 沙盒環境 <a href="#sandbox-environment" id="sandbox-environment"></a>

* 執行環境是**安全沙盒**，與正式系統隔離，不會影響其他資料
* 支援標準 Python 與常見資料／文件處理套件
* Agent 產生的檔案會出現在聊天介面的 **Output** 面板，可直接下載

## 適合的場景 <a href="#when-to-use" id="when-to-use"></a>

* 內部財務／銷售團隊請 Agent 整理 Excel、產出每週報表
* HR／行政請 Agent 把問卷結果做成圖表、產出 PowerPoint
* 法務／合約團隊請 Agent 從 PDF 抽取關鍵欄位、輸出 Word 摘要
* 任何需要「即席計算」或「即席生成檔案」的對話場景

## 我需要做什麼？ <a href="#what-do-i-need-to-do" id="what-do-i-need-to-do"></a>

1. **進入 Agent 設定** — 在你想啟用的 AI 助理設定頁
2. **開啟 Code Interpreter** — 在工具或進階能力區啟用
3. **測試** — 在對話中請 Agent 做一件需要計算或產檔的任務，確認 Output 面板能正常下載


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.maiagent.ai/agent-builder/code-interpreter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
