python-shell-fallback
できること
このスキルは、サンドボックスにパッケージがないときに、ライブラリに依存するPythonの作業をシェルに移す方法をAIエージェントに示します。PDFやグラフなどライブラリを多く使う出力が必要な人向けです。
使う場面
- ✓サンドボックスが、ModuleNotFoundErrorや同様のインポートのエラーを返すとき。
- ✓サンドボックスにないライブラリが必要なPDFやグラフが必要なとき。
- ✓サンドボックスでの実行が、パッケージの問題で失敗し続けるとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-shell-fallback/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このテキストからPDFレポートを作ってください。サンドボックスではモジュールがないと言われるので、代わりにシェルで実行してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、パッケージが足りないというエラーを見つけ、コードをheredocを使ってシェル経由で実行するように書き換えます。シェルの環境には、インストール済みのパッケージがより多くあるのが普通です。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Python Shell Fallback
When execute_code_sandbox fails for Python code that depends on external libraries, use run_shell with a heredoc Python script as a reliable fallback. The shell environment typically has better access to installed packages and system configuration than the sandbox.
When to Use This Pattern
Apply this skill when:
execute_code_sandboxreturns errors related to missing libraries (e.g.,ModuleNotFoundError)- The code requires packages that may not be installed in the sandbox environment
- You need PDF generation, data visualization, or other library-heavy operations
- Previous sandbox execution attempts have failed with import errors
How to Implement
Step 1: Identify the Failure
Check if the sandbox error indicates a library/dependency issue:
ModuleNotFoundError: No module named 'xxx'ImportError: cannot import name 'xxx'- Similar package-related errors
Step 2: Convert to Shell Execution
Rewrite the code execution using run_shell with a heredoc:
python3 << 'EOF'
# Your Python code here
import library_name
# ... rest of code
EOF
Step 3: Execute via run_shell
Call run_shell with the heredoc Python script:
command: python3 << 'EOF'
import reportlab
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
# Your library-dependent code here
c = canvas.Canvas("output.pdf", pagesize=letter)
c.drawString(100, 750, "Hello World")
c.save()
EOF
Example: PDF Generation Fallback
Sandbox attempt (fails):
# execute_code_sandbox call fails with:
# ModuleNotFoundError: No module named 'reportlab'
Shell fallback (works):
python3 << 'EOF'
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas("legal_memo.pdf", pagesize=letter)
c.setTitle("Legal Memorandum")
c.drawString(100, 750, "CONFIDENTIAL LEGAL MEMORANDUM")
c.save()
print("PDF created successfully")
EOF
Best Practices
- Use quoted heredoc (
<< 'EOF') - Prevents variable expansion, keeping Python code intact - Verify output - Check stdout/stderr from
run_shellto confirm success - Handle file paths - Ensure output files are written to accessible directories
- Test incrementally - For complex scripts, test in smaller chunks first
- Include error handling - Add try/except blocks to capture issues gracefully
Alternative: Inline Python Command
For simple one-liners or short scripts:
python3 -c "import reportlab; print(reportlab.__version__)"
Troubleshooting
If shell execution also fails:
- Check if Python3 is available:
which python3 - Verify package installation:
pip3 list | grep package_name - Try
pythoninstead ofpython3(some systems differ) - Consider installing the package:
pip3 install package_name
よくある質問
どのエラーが切り替えの合図になりますか?
ModuleNotFoundErrorやパッケージに関するImportErrorなどが、切り替えの合図です。
PDFも作れますか?
reportlabなどのライブラリでPDFを生成する例が、一つ挙げられています。
これは常にうまくいきますか?
シェルにパッケージがあることを前提にしているため、そこにインストールされていなければ失敗することもあります。
詳細
作者による元の説明
Fallback to shell execution when sandbox fails for library-dependent Python code
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #12961
- ライセンス
- 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のイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。