shell-python-fallback
できること
このスキルは、コードツールが原因不明のエラーを返したとき、AIエージェントにPythonの代替手段を示します。データ処理やPDF作成を確実に終わらせたい人向けです。
使う場面
- ✓同じ作業でコードツールが原因不明のエラーを2回以上返したとき。
- ✓データ処理、ファイル解析、PDF作成をPythonで行う必要があるとき。
- ✓スクリプトを実行し、確認できる明確な出力がほしいとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/shell-python-fallback/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“コードツールが、このデータ整理で原因不明のエラーを返し続けています。Pythonをシェルで実行して、出力を見せてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、ヒアドキュメントを使ってPythonスクリプトをシェルコマンドに埋め込みます。実行し、表示された出力を読んで成功かエラーかを確認し、必要ならコードを調整します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Shell Python Fallback
When to Use
Use this pattern when execute_code_sandbox or shell_agent tools consistently fail with "unknown error" for tasks such as:
- Data processing and transformation
- PDF generation (reportlab, etc.)
- File parsing and manipulation
- Any Python script execution that requires reliability
The Pattern
Instead of using code execution tools, embed your Python script directly in a run_shell command using a heredoc:
python3 << 'EOF'
# Your Python code here
import sys
print("Hello from embedded Python")
EOF
Step-by-Step Instructions
Identify the failure: When
execute_code_sandboxorshell_agentreturns "unknown error" repeatedly (2+ attempts), switch to this fallback.Write your Python script: Prepare the complete Python code you need to execute.
Embed in run_shell: Use
run_shellwith a heredoc syntax:
Command: python3 << 'EOF'
import json
# Your complete script here
data = {"key": "value"}
print(json.dumps(data))
EOF
Handle multi-line scripts: For longer scripts, ensure proper indentation is preserved. The heredoc preserves whitespace exactly.
Check output: Parse the stdout from
run_shellto verify success or capture errors.
Example: PDF Generation
python3 << 'EOF'
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas("output.pdf", pagesize=letter)
c.drawString(100, 750, "Hello World")
c.save()
print("PDF created successfully")
EOF
Example: Data Processing
python3 << 'EOF'
import csv
import json
data = []
with open('input.csv', 'r') as f:
reader = csv.DictReader(f)
for row in reader:
data.append(row)
with open('output.json', 'w') as f:
json.dump(data, f, indent=2)
print(f"Processed {len(data)} records")
EOF
Best Practices
- Quote the EOF delimiter (
<< 'EOF'not<< EOF) to prevent shell variable expansion in your Python code - Include error handling in your Python script with try/except blocks
- Print status messages to stdout so you can verify execution succeeded
- Use absolute paths or ensure working directory is correct
- Test incrementally: Start with a minimal script, then expand
Troubleshooting
| Issue | Solution |
|---|---|
| Script doesn't run | Ensure python3 is available in the shell environment |
| Indentation errors | Check that heredoc preserves spaces (use spaces, not tabs) |
| Module not found | Use python3 -m pip install <module> before running script |
| File not found | Use absolute paths or pwd to verify working directory |
Why This Works
The run_shell tool executes commands directly in the system shell, bypassing the sandbox restrictions or internal errors that affect execute_code_sandbox and shell_agent. The heredoc approach allows multi-line Python scripts while keeping everything in a single shell command.
よくある質問
何回失敗したら切り替えますか?
スキルは、原因不明のエラーが2回以上出たら切り替えるよう述べています。
ヒアドキュメントはインデントを保ちますか?
はい。スキルは、ヒアドキュメントが空白を正確に保つため、複数行のコードがそのまま残ると述べています。
PDFも作れますか?
はい。スキルは、reportlabを使ったPDFの例を示しています。
詳細
作者による元の説明
Use run_shell with embedded Python heredoc as reliable fallback when code execution tools fail
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #13001
- ライセンス
- MIT
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
agentpilot
7.8kエージェントが、作業を準備し、変更案を提案してテストし、評価するAgentPilotのループを実行することで、プロジェクトを段階的に改善できるよう支援します。
openspace
7.8kエージェントが、スキルを保存し取り出すツールであるOpenSpaceをセットアップし、MCPを通じてAIアプリに接続できるよう支援します。
rsi-arena
7.8kエージェントが、AIMEやTerminal-Benchなどの標準的なAIベンチマークテストをセットアップして実行し、異なる改善方法を比較できるよう支援します。
experiment-guide
7.8kエージェントが、プログラムを改善する方法を調べる間に、小さな実験を計画し、その結果を読み、発見を記録できるよう支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。