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

run-shell-fallback

できること

このスキルは、ファイルリーダーやコードのサンドボックスが壊れたときの、信頼できる予備の方法をAIエージェントに与えます。単純なタスクでも不明なエラーが返ってくるAIツールを使っている人向けです。

使う場面

  • ✓コードのサンドボックスが、不明なエラーやタイムアウトで失敗するとき。
  • ✓存在が確かなファイルを、ファイルリーダーが開けないとき。
  • ✓タスクを進めるために、単純なファイルの読み取りや短いPythonの計算が必要なとき。

スキルのリンク

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

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

使い方

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

貼り付け用メッセージ

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

AIへの頼み方の例

“ファイルリーダーがnotes.txtというファイルで失敗し続けています。シェルで読んで、中身を教えてください。”

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

仕組み

エージェントは、テキストファイルの読み取りにはcatを使い、構造化された解析や短い計算には、シェル経由のインラインのPythonを使います。コマンドを実行して、表示された出力を読みます。

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

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

Run Shell Fallback Pattern

This skill provides a reliable workaround when execute_code_sandbox or read_file fail with 'unknown error' by switching to run_shell with inline Python code.

When to Use

Apply this pattern when you encounter:

  • execute_code_sandbox fails with "unknown error" or timeout
  • read_file fails to read accessible files with "unknown error"
  • Sandbox environment is unreliable for your specific task

How to Implement

1. File Reading Fallback

When read_file fails, use run_shell with Python or cat:

For text files:

run_shell(command="cat /path/to/file.txt")

For structured parsing (Python one-liner):

run_shell(command="python3 -c \"import json; print(json.load(open('/path/to/file.json')))\"")

For multi-line Python processing:

run_shell(command="python3 << 'EOF'
with open('/path/to/file.txt', 'r') as f:
    content = f.read()
    # Process content here
    print(content.upper())
EOF")

2. Code Execution Fallback

When execute_code_sandbox fails, use run_shell with inline Python:

Simple one-liners:

run_shell(command="python3 -c \"print('Hello'); import os; print(os.getcwd())\"")

Multi-line scripts (heredoc):

run_shell(command="python3 << 'EOF'
import os
import json

def process_data(data):
    return {k: v.upper() if isinstance(v, str) else v for k, v in data.items()}

with open('input.json') as f:
    data = json.load(f)
    
result = process_data(data)
print(json.dumps(result, indent=2))
EOF")

With inline file write:

run_shell(command="python3 << 'EOF'
result = {'status': 'success', 'count': 42}
with open('output.json', 'w') as f:
    json.dump(result, f, indent=2)
print('File written successfully')
EOF")

3. Decision Flow

1. Attempt execute_code_sandbox or read_file
2. If failure with 'unknown error':
   a. Determine task type (code execution vs file reading)
   b. Choose inline Python approach (-c for simple, heredoc for complex)
   c. Execute via run_shell
   d. Parse output as needed
3. Continue with task using results from run_shell

Best Practices

  1. Escape quotes properly in -c commands: Use \" for double quotes inside the command string

  2. Use heredoc for complex scripts: When code exceeds 2-3 lines or needs multiple imports, use << 'EOF' syntax

  3. Quote EOF marker: Use << 'EOF' (with quotes) to prevent variable expansion in the heredoc

  4. Capture stdout: Design your inline Python to print results to stdout for easy capture

  5. Error handling: Add try/except blocks in your inline Python to catch and report errors clearly

  6. File paths: Use absolute paths when possible, or ensure working directory is correct

Examples

Example 1: Read and parse JSON after read_file failure

run_shell(command="python3 -c \"import json; data=json.load(open('config.json')); print(data['key'])\"")

Example 2: Process CSV data after execute_code_sandbox failure

run_shell(command="python3 << 'EOF'
import csv
with open('data.csv', 'r') as f:
    reader = csv.DictReader(f)
    rows = list(reader)
    print(f\"Total rows: {len(rows)}\")
    for row in rows[:5]:
        print(row)
EOF")

Example 3: Transform and write output file

run_shell(command="python3 << 'EOF'
import json
with open('input.json') as f:
    data = json.load(f)
transformed = [item.upper() if isinstance(item, str) else item for item in data]
with open('output.json', 'w') as f:
    json.dump(transformed, f, indent=2)
print('Transformation complete')
EOF")

Limitations

  • run_shell executes in the shell environment, not the sandbox - ensure paths and dependencies are available
  • Output is limited to stdout/stderr - use file writes for large data
  • Complex multi-file projects may require creating temporary script files first
よくある質問

テキストファイルを読むコマンドは?

ファイルの内容をシェルに表示するcatを使います。

JSONファイルを解析できますか?

はい。スキルは、JSONファイルを読み込んで表示する一行のPythonのコマンドを示しています。

長いスクリプトにインラインのPythonは安全ですか?

複数行のスクリプトには、長いコードを読みやすく保つheredocを使うとスキルは述べています。

詳細

作者による元の説明

Use run_shell with inline Python as a reliable fallback when execute_code_sandbox or read_file fail

repo: HKUDS/AgentPilot

人気

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

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

0

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

コメント

  • …

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

似ているスキル