本文へスキップ
Skillpedia
一般的なプログラミング7.8k · #12992

sandbox-fallback-python

できること

このスキルは、サンドボックスに接続できないとき、AIエージェントがシェルでPythonを実行するよう導きます。パッケージやファイル出力に依存するPythonの作業を行う人向けです。

使う場面

  • ✓サンドボックスが利用不可か接続失敗を表示したとき。
  • ✓Pythonスクリプトを実行する前に、パッケージをインストールする必要があるとき。
  • ✓ワークスペースフォルダーのファイルを読み書きする必要があるとき。

スキルのリンク

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-fallback-python/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-fallback-python/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“サンドボックスが利用できません。スクリプトに必要なパッケージをインストールして実行し、出力をワークスペースに保存してください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、pipでパッケージをインストールし、ヒアドキュメントを使ってシェルからPythonコードを実行します。ファイルには明示的なパスを使い、フォルダーの一覧で出力が保存されたかを確認します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Sandbox Fallback: Python via run_shell

When to Use This Skill

Apply this skill when execute_code_sandbox fails with errors indicating:

  • e2b service unavailability
  • Sandbox timeout or connection issues
  • Code execution environment not accessible

This fallback allows you to execute Python code directly via shell, bypassing the sandbox infrastructure.

Fallback Procedure

Step 1: Detect Sandbox Failure

Identify fallback necessity from error messages like:

  • "e2b unavailable"
  • "sandbox connection failed"
  • "execution environment error"
  • Timeout errors during code execution

Step 2: Switch to run_shell with Embedded Python

Instead of execute_code_sandbox, use run_shell with a Python heredoc or inline script:

python3 << 'EOF'
# Your Python code here
print("Hello from fallback execution")
EOF

Step 3: Install Dependencies First

If your Python code requires packages not guaranteed to be installed:

pip install package_name package_name2 && python3 << 'EOF'
# Your Python code here
import package_name
print("Code with dependencies executed")
EOF

Step 4: Handle File I/O

For scripts that need to read/write files:

  • Use absolute or explicit relative paths
  • Files persist in the workspace directory
  • List directory contents with ls to verify file operations
python3 << 'EOF'
import os
# Write output to file
with open("output.txt", "w") as f:
    f.write("Results here")
# Verify
print(f"Working directory: {os.getcwd()}")
EOF

Code Examples

Simple Calculation

python3 << 'EOF'
result = sum(range(100))
print(f"Sum: {result}")
EOF

With Package Installation

pip install requests -q && python3 << 'EOF'
import requests
response = requests.get("https://api.example.com/data")
print(response.json())
EOF

With JSON Processing

python3 << 'EOF'
import json

data = {"key": "value", "count": 42}
output = json.dumps(data, indent=2)
print(output)

# Save to file
with open("data.json", "w") as f:
    f.write(output)
EOF

Best Practices

  1. Use heredoc syntax - << 'EOF' prevents variable expansion issues
  2. Install quietly - Use pip install -q to reduce output noise
  3. Error handling - Add try/except blocks in Python code for robustness
  4. Verify execution - Check stdout/stderr from run_shell to confirm success
  5. Keep code compact - Long scripts are harder to debug in shell context

Caveats

  • No persistent state between run_shell calls (unlike execute_code_sandbox)
  • Longer execution time for complex scripts due to Python interpreter startup
  • Limited debugging - Cannot easily inspect variables between statements
  • Output size limits - Very large outputs may be truncated

When NOT to Use This Fallback

  • If the task specifically requires sandbox isolation for security
  • If you need persistent state across multiple code executions
  • If the code execution is extremely long-running (consider backgrounding)
よくある質問

エージェントは出力をどのように確認しますか?

シェルのメッセージを読み、フォルダーを一覧表示して新しいファイルを確認します。

なぜ明示的なパスを使うのですか?

ファイルが想定しているワークスペースフォルダーに保存されるようにするためです。

何もインストールせずに動きますか?

パッケージがすでにあれば、インストール手順を省略できます。

詳細

作者による元の説明

Fallback to run_shell with embedded Python when execute_code_sandbox fails due to e2b unavailability

repo: HKUDS/AgentPilot

人気

GitHubのスター
7.8k
ランキング
#12992
ライセンス
MIT
更新日
2026/11/1

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル