fallback-python-execution
它能做什么
这项技能是当沙箱或辅助智能体无法运行 Python 时的备用方法。它适合需要 Python 来生成数据或文档文件的人。
适用场景
- ✓当沙箱返回未知错误或反复失败的时候。
- ✓当我需要 Python 制作电子表格、文档或数据文件的时候。
- ✓当辅助智能体无法正确运行 Python 代码的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-python-execution/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“辅助工具无法运行我的 Python 脚本来制作电子表格。请把脚本保存为文件,并直接运行它。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会把完整的 Python 代码写入 .py 文件,用 shell 命令运行它,检查预期的文件是否生成,之后可以选择删除脚本。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Fallback Python Execution Pattern
When to Use
Use this pattern when:
execute_code_sandboxreturns unknown errors or fails repeatedlyshell_agentcannot successfully execute Python code- You need to create files (spreadsheets, documents, data files) via Python
- Direct delegated approaches prove unreliable in the current environment
Core Technique
Instead of delegating Python execution to agents, use this two-step inline approach:
- Write Python code to a
.pyfile usingwrite_file - Execute the file using
run_shellwithpython <script.py>
Step-by-Step Instructions
Step 1: Write Python Code to File
Use write_file to create a Python script with all necessary code inline:
write_file
path: /path/to/script.py
content: |
import pandas as pd
# Your complete Python code here
df = pd.DataFrame({...})
df.to_excel('output.xlsx', index=False)
Step 2: Execute via run_shell
Run the script directly:
run_shell
command: python /path/to/script.py
Step 3: Verify and Clean Up
- Check the output for success/errors
- Verify the expected files were created
- Optionally remove the temporary script if no longer needed
Why This Works
This approach is more reliable because:
- Avoids agent interpretation layers that can introduce errors
- Provides direct control over execution environment
- Gives clear error output for debugging
- Bypasses sandbox delegation issues
Example: Excel File Creation
# Step 1: Write the script
write_file:
path: create_report.py
content: |
import pandas as pd
from openpyxl import Workbook
# Create data
data = {'Column1': [1, 2, 3], 'Column2': ['A', 'B', 'C']}
df = pd.DataFrame(data)
# Save to Excel
df.to_excel('report.xlsx', index=False)
print('Excel file created successfully')
# Step 2: Execute
run_shell:
command: python create_report.py
Tips
- Include error handling in your Python code for better debugging
- Use absolute paths when possible to avoid working directory issues
- Add print statements to track execution progress
- Keep scripts self-contained with all imports at the top
- For complex tasks, break into multiple scripts if needed
Troubleshooting
| Issue | Solution |
|---|---|
| Module not found | Add pip install commands before python command |
| Permission errors | Check file paths are writable |
| Script not found | Use absolute path or cd to directory first |
| Output not created | Check for Python errors in run_shell output |
常见问题
为什么要避开辅助智能体?
指南说,这种方式避免了可能引入错误的额外解释层。
之后可以删除脚本吗?
可以。删除临时脚本是可选的最后一步。
最后应该检查什么?
输出中是否有成功或错误信息,以及预期的文件是否已生成。
详情
作者的原始描述
Reliable Python execution workflow when execute_code_sandbox or shell_agent fail
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12882
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。