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。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“文件读取器一直无法读取我的 notes.txt 文件。请用 shell 读取它,并告诉我它的内容。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会使用 cat 读取文本文件,并通过 shell 运行内联 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_sandboxfails with "unknown error" or timeoutread_filefails 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
Escape quotes properly in
-ccommands: Use\"for double quotes inside the command stringUse heredoc for complex scripts: When code exceeds 2-3 lines or needs multiple imports, use
<< 'EOF'syntaxQuote EOF marker: Use
<< 'EOF'(with quotes) to prevent variable expansion in the heredocCapture stdout: Design your inline Python to print results to stdout for easy capture
Error handling: Add try/except blocks in your inline Python to catch and report errors clearly
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
常见问题
哪个命令用于读取文本文件?
这项技能在 shell 中使用 cat 打印文件内容。
它能解析 JSON 文件吗?
可以。这项技能展示了一条单行 Python 命令,可以加载并打印 JSON 文件。
内联 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
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。