debug-sandbox-execution
Skill này làm gì
Skill này là phương pháp gỡ lỗi các lần chạy code Python thất bại với lỗi mơ hồ hoặc kết quả chưa đầy đủ. Dành cho người cần tìm bước nào bị hỏng và làm code chạy lại được.
Khi nào nên dùng
- ✓Khi một lần chạy code thất bại với lỗi không rõ hoặc dừng với kết quả chưa đầy đủ.
- ✓Khi một script tạo ra nhiều tệp nhưng chỉ một số tệp xuất hiện.
- ✓Khi tôi muốn kiểm tra riêng từng phần của script để tìm bước lỗi.
Liên kết skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/debug-sandbox-execution/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Script Python của tôi dừng giữa chừng mà không có lỗi rõ ràng. Bạn có thể giúp tôi tìm phần nào đang lỗi không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
AI chạy lại script để thu thập mọi kết quả xuất hiện trước khi lỗi, kiểm tra từng hàm riêng, rồi kiểm tra kết quả từng bước để tìm nguyên nhân.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Vì sao phải thu thập kết quả một phần?
Nó cho thấy các bước nào đã chạy thành công và lỗi xảy ra ở đâu.
Skill có tự sửa code không?
Chủ yếu nó tìm nguyên nhân và khôi phục theo từng bước, còn việc sửa dựa trên những gì được tìm thấy.
Nó dùng lệnh nào?
Nó dùng chuyển hướng đầu ra shell để thu thập kết quả, và chạy thử riêng cho từng khối code.
Chi tiết
Mô tả gốc của tác giả
Debug Python code execution failures by capturing partial traces, isolating failing functions, and incrementally verifying outputs
repo: HKUDS/AgentPilot
Độ phổ biến
- Sao GitHub
- 7.8k
- Vị trí xếp hạng
- #12850
- Giấy phép
- MIT
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
agentpilot
7.8kGiúp agent của bạn cải thiện dự án từng bước bằng cách chuẩn bị tác vụ và chạy vòng lặp AgentPilot, gồm đề xuất, kiểm thử và chấm điểm thay đổi.
openspace
7.8kGiúp agent của bạn thiết lập OpenSpace, công cụ lưu và lấy lại skill của agent, rồi kết nối nó với ứng dụng AI của bạn qua MCP.
rsi-arena
7.8kGiúp agent của bạn thiết lập và chạy các bài kiểm thử benchmark AI chuẩn, như AIME và Terminal-Bench, để so sánh các phương pháp cải tiến khác nhau.
experiment-guide
7.8kGiúp agent của bạn lên kế hoạch các thí nghiệm nhỏ, đọc kết quả và ghi lại phát hiện khi tìm cách cải thiện một chương trình.
Skill tương tự
test-driven-development
311kDạy agent của bạn viết kiểm thử thất bại trước, xem nó thất bại, rồi viết đoạn mã ngắn nhất để vượt qua trước khi làm bất kỳ tính năng hay bản sửa nào.
verification-before-completion
311kDạy agent của bạn chạy kiểm tra thực tế và đọc kết quả đầu ra trước khi khẳng định một việc, bản sửa hoặc bản build đã hoàn thành hay vượt qua.
migrate-to-shoehorn
310kThay các ép kiểu rủi ro trong tệp kiểm thử bằng thư viện shoehorn, để các bài kiểm thử dùng dữ liệu một phần vẫn qua được kiểm tra kiểu.