fallback-script-execution
它能做什么
这项技能是一种可重复使用的两步法运行 Python 脚本的方法,能给出更清晰的错误信息。它适合调试那些无法通过常用工具运行的代码的人。
适用场景
- ✓当辅助智能体在运行代码时反复失败并给出含糊信息的时候。
- ✓当沙箱对同一段代码超时或报错的时候。
- ✓当我希望修改并重新运行脚本,而不必每次重写的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-script-execution/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“辅助智能体在运行我的脚本时一直失败。请把脚本保存为文件并运行,让我能看到完整的错误。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会把一个包含错误处理的独立脚本写入文件,然后用 shell 命令运行它,使完整的堆栈跟踪和输出都可见。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Fallback Script Execution with write_file + run_shell
When to Use This Skill
Use this pattern when:
shell_agentfails repeatedly with unclear error messagesexecute_code_sandboxconsistently errors or times out- You need better visibility into what's happening during execution
- Debugging inline code or delegated agents proves difficult
Core Pattern
Instead of delegating execution to an agent or running inline code, use this two-step approach:
- Write script to file using
write_file - Execute script using
run_shellwithpython script.py
This provides:
- Clearer error messages (full stack traces visible in run_shell output)
- Easier debugging (script persists for inspection)
- Better control over execution environment
- Ability to modify and re-run without rewriting code
Step-by-Step Instructions
Step 1: Write the Script File
Use write_file to create a self-contained Python script:
write_file with:
path: "path/to/script_name.py"
content: |
#!/usr/bin/env python3
# Your complete script here
# Include imports, logic, and error handling
Best Practices:
- Include descriptive comments
- Add try/except blocks for error handling
- Print intermediate results for debugging
- Use absolute or clear relative paths
Step 2: Execute the Script
Use run_shell to execute the script:
run_shell with:
command: "python path/to/script_name.py"
Best Practices:
- Capture and examine full output
- If errors occur, the script file is still available for inspection
- You can re-run with modifications without starting over
Example: Data Processing Task
❌ Problematic Approach (shell_agent fails repeatedly)
shell_agent with:
task: "Load Excel file, calculate correlations, save results"
Result: Agent struggles with path handling, unclear errors
✅ Recommended Approach (write_file + run_shell)
# Step 1: Write script
write_file with:
path: "correlation_analysis.py"
content: |
import pandas as pd
import sys
try:
# Load data
df = pd.read_excel('data.xlsx', sheet_name='Returns')
print(f"Loaded {len(df)} rows")
# Calculate correlation
corr = df.corr()
print(f"Correlation matrix shape: {corr.shape}")
# Save results
with pd.ExcelWriter('output.xlsx') as writer:
df.to_excel(writer, sheet_name='Returns')
corr.to_excel(writer, sheet_name='Correlation')
print("SUCCESS: output.xlsx created")
except Exception as e:
print(f"ERROR: {type(e).__name__}: {e}", file=sys.stderr)
sys.exit(1)
# Step 2: Execute script
run_shell with:
command: "python correlation_analysis.py"
Debugging Tips
- Add print statements at key points to trace execution
- Check file paths - use
run_shellwithls -la path/to verify files exist - Inspect errors - run_shell output shows full Python stack traces
- Modify and re-run - edit the script file and execute again without rewriting
When to Escalate
If this pattern also fails:
- Verify Python is available:
run_shellwithwhich pythonorpython --version - Check file permissions:
run_shellwithls -la script.py - Try explicit Python path:
run_shellwith/usr/bin/python script.py - Consider task complexity - may need to break into smaller scripts
常见问题
为什么文件更利于调试?
脚本保存在磁盘上,修改后可以检查并再次运行。
什么让错误输出更清晰?
完整的堆栈跟踪会显示在 shell 输出中,而不是被隐藏。
脚本应包含什么?
导入、主要逻辑、try 和 except 代码块,以及打印的进度信息。
详情
作者的原始描述
Two-step script execution workflow for debugging when shell_agent and execute_code_sandbox consistently fail
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12884
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。