python-debug-execution
What it does
This skill explains a simple way for the AI agent to run and debug Python code with clear error output. It is for people who run Python scripts through an AI.
When to use it
- ✓When a Python script stops and you cannot tell why.
- ✓When file operations in a script fail and the folder may be wrong.
- ✓When you want the AI to list the folder contents to check that files are where they should be.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-execution/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“My script keeps failing on a file path. Help me debug it and show me what folder it is running in.”
5 new skills a week. 1 minute to read.
How it works
The agent runs the script with error output captured and the exit code printed. It adds checks that print the working directory and the files in it before the script reads or writes anything.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Python Debug Execution Pattern
When executing Python scripts that may fail, use this pattern to surface clear error information and diagnose issues effectively.
Core Technique
1. Execute with Full Error Output
Always run Python scripts with stderr redirected to stdout and echo the exit code:
python3 script.py 2>&1 ; echo Exit code: $?
Why this works:
2>&1captures both stdout and stderr, ensuring tracebacks are visibleecho Exit code: $?reveals the actual exit status for debugging- Avoids opaque "command failed" errors that hide the real cause
2. Verify Working Directory in Script
Before any file operations in Python scripts, add working directory verification:
import os
# At the start of your script or before file operations
print(f"Current working directory: {os.getcwd()}")
# For debugging, also list directory contents
print(f"Directory contents: {os.listdir('.')}")
Why this works:
- File not found errors often stem from incorrect working directory assumptions
- Makes path-related failures immediately diagnosable
- Confirms the execution context matches expectations
Complete Debugging Workflow
Step 1: Add Diagnostic Code to Script
#!/usr/bin/env python3
import os
import sys
def main():
# Diagnostic: verify execution context
print(f"Working directory: {os.getcwd()}")
print(f"Python version: {sys.version}")
print(f"Directory listing: {os.listdir('.')}")
# Your actual logic here
# ...
if __name__ == "__main__":
main()
Step 2: Execute with Full Error Capture
python3 script.py 2>&1 ; echo Exit code: $?
Step 3: Analyze Output
Look for:
- Traceback messages (indicate code errors)
- Exit code (0 = success, non-zero = failure)
- Working directory confirmation
- Missing file/directory errors
Common Failure Patterns
| Symptom | Likely Cause | Debug Clue |
|---|---|---|
| FileNotFoundError | Wrong working directory | Check os.getcwd() output |
| ModuleNotFoundError | Missing dependencies | Traceback shows import path |
| PermissionError | File access issues | Traceback shows file path |
| Silent failure (exit 0, no output) | Logic bug, not crash | Add print statements |
When to Use This Pattern
- Running Python scripts in automated/agent contexts
- Debugging scripts that interact with files
- Troubleshooting CI/CD pipeline failures
- Any scenario where script output may be truncated or hidden
FAQ
Why list the folder contents?
Seeing which files are present often shows why a file cannot be found.
Does this only work for one kind of script?
No, the steps apply to any Python script that reads or writes files.
Do I need to know Python?
No, the agent handles the commands and explains what each output means.
Details
Original description by the author
Debug Python scripts with proper error surfacing and working directory verification
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #12956
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.