debug-sandbox-execution
它能做什么
这项技能是一种调试方法,用于排查输出含糊或不完整的 Python 代码运行失败问题。它适合需要找出哪一步出错并让代码重新运行的人。
适用场景
- ✓当代码运行因未知错误失败,或输出不完整就停止的时候。
- ✓当脚本生成了多个文件,但只出现了其中一部分的时候。
- ✓当我想单独测试脚本的每一部分,以找出出错的步骤的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/debug-sandbox-execution/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的 Python 脚本运行到一半就停了,也没有明确的错误信息。你能帮我找出是哪一部分出了问题吗?”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会重新运行脚本,捕获失败之前出现的任何输出,单独测试每个函数,并逐一检查结果以找出原因。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Debug Sandbox Execution Failures
When execute_code_sandbox fails with unknown errors or incomplete output, use this debugging pattern to identify the root cause and recover incrementally.
Problem
The execute_code_sandbox tool may fail silently, truncate output, or produce opaque errors. Complex scripts with multiple file outputs are especially prone to partial failures.
Solution
Use a three-phase debugging approach:
Phase 1: Capture Partial Execution Traces
When a sandbox execution fails, rerun the code using run_shell with output piping to capture whatever output is produced before the failure:
python your_script.py 2>&1 | head -100
This reveals:
- Which functions/steps executed successfully
- Where the failure occurred
- Any error messages that were suppressed
Phase 2: Isolate Failing Functions
Break the script into smaller, testable units. Execute each function or code block independently:
# Test individual components
if __name__ == "__main__":
# Step 1: Test imports
import numpy as np
print("Imports OK")
# Step 2: Test function A in isolation
result_a = function_a()
print(f"Function A: {result_a}")
# Step 3: Test function B
result_b = function_b(result_a)
print(f"Function B: {result_b}")
Run each section with execute_code_sandbox separately to identify which component fails.
Phase 3: Incremental Output Generation
Generate output files one at a time, verifying each before proceeding:
import numpy as np
import soundfile as sf
# Generate and save file 1
audio1 = np.random.randn(48000 * 10).astype(np.float32)
sf.write('output_01.wav', audio1, 48000, subtype='FLOAT')
# Verify file 1 exists and has expected properties
import os
assert os.path.exists('output_01.wav'), "File 1 not created"
# Generate and save file 2
audio2 = np.random.randn(48000 * 10).astype(np.float32)
sf.write('output_02.wav', audio2, 48000, subtype='FLOAT')
# Verify file 2
assert os.path.exists('output_02.wav'), "File 2 not created"
Example Workflow
- Initial attempt: Run full script with
execute_code_sandbox - On failure: Rerun with
run_shelland| head -100to see partial output - Identify breakpoint: Find the last successful operation
- Split script: Create separate scripts for each major section
- Test incrementally: Run each section, verify outputs, proceed to next
- Combine successful sections: Once all pieces work, combine into final script
Best Practices
- Always verify file creation immediately after writing:
assert os.path.exists(path) - Check file properties (size, duration, format) before assuming success
- Use print statements liberally to mark progress through the script
- Save intermediate outputs so failures don't require restarting from scratch
- Test audio/video generation with short samples first (1-2 seconds) before full-length content
When to Use
- Complex scripts with multiple file outputs
- Audio/video generation pipelines
- Scripts with external library dependencies
- Any
execute_code_sandboxcall that produces incomplete or no output
常见问题
为什么要捕获部分输出?
它可以显示哪些步骤已成功运行,以及失败发生在哪里。
它会自己修复代码吗?
它主要负责找出原因并分步恢复,修复方案则依据查明的结果而定。
它使用哪些命令?
它使用 shell 输出管道来捕获结果,并对每段代码分别进行测试运行。
详情
作者的原始描述
Debug Python code execution failures by capturing partial traces, isolating failing functions, and incrementally verifying outputs
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12850
- 许可证
- 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帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。