# 代码解释器

> 在沙箱中运行 Python，仅在宿主显式启用时注册。

Source: https://kcq.nebutra.com/zh/docs/agent/tools/code-interpreter


<Callout>
  由固定提交的图表源码生成（

  [`1aa5e22`](https://github.com/TsekaLuk/KLineChartQuant/blob/1aa5e22c61313a34d08878ad895e604e0d4a85e9/packages/core/src/foundation/agent/chartToolRegistry.ts)

  ）。工具说明保留模型实际收到的英文原文，不做翻译。
</Callout>

code_interpreter [#code_interpreter]

<ToolMeta label="Run Python" safety="destructive" safetyLabel="修改图表" mode="按序执行" origin="可选" source="https://github.com/TsekaLuk/KLineChartQuant/blob/1aa5e22c61313a34d08878ad895e604e0d4a85e9/packages/agent-runtime/src/tools/code-interpreter/tool.ts#L11" sourceLabel="源码" />

Execute Python code in an isolated sandbox with numpy and pandas available and outbound network disabled. Read inputs from $INPUT\_DIR and write files you want returned into $OUTPUT\_DIR.

**参数**

| 字段                             | 类型                     | 必填 | 约束                                                     | 说明                                                                                       |
| ------------------------------ | ---------------------- | -- | ------------------------------------------------------ | ---------------------------------------------------------------------------------------- |
| <code>code</code>              | <code>string</code>    | 是  | min length <code>1</code>                              | Python source to execute. Only the standard library plus numpy and pandas are available. |
| <code>files</code>             | <code>object\[]</code> | —  | max items <code>16</code>                              |                                                                                          |
| <code>files\[].name</code>     | <code>string</code>    | —  | min length <code>1</code>; max length <code>255</code> |                                                                                          |
| <code>files\[].content</code>  | <code>string</code>    | —  | —                                                      |                                                                                          |
| <code>files\[].encoding</code> | <code>enum</code>      | —  | one of <code>"utf8", "base64"</code>                   |                                                                                          |
| <code>timeoutMs</code>         | <code>integer</code>   | —  | ≥ <code>1</code>; ≤ <code>60000</code>                 |                                                                                          |

**最小输入** · 仅含必填字段，占位值由 schema 推导。

```json
{
  "code": "<code>"
}
```

<ToolSchema name="code_interpreter" label="JSON Schema" />
