Anthropic 员工讲解 Claude Code 自定义工具接入代码执行容器的用法
Anthropic 开发者关系员工 Ado Kukic 介绍如何用 allowed_callers: ["code_execution_20260120"] 字段把自定义工具接入代码执行容器,工具会以 async Python 函数形式出现,Claude 可用循环、分支和 asyncio.gather 调用它。每次调用会暂停脚本并返回一个普通 tool_use block,结果返回给运行中的代码而非模型,Claude 读取脚本打印的内容。他提醒:每次 continuation 都要回传容器 id,并在工具描述中写清输出结构。
The field is allowed_callers: ["code_execution_20260120"]. Your tool then shows up inside the code execution container as an async Python function, so Claude can loop, branch and asyncio.gather over it.
Each call pauses the script and hands you a normal tool_use block. You return the result to the running code, not to the model. Claude reads what the script prints.
Non-obvious: send the container id back on every continuation, and describe your output shape in the tool description.
来源:Ado · x.com