run-shell-fallback
Skill này làm gì
Skill này cho AI agent một phương án dự phòng đáng tin cậy khi trình đọc file hoặc sandbox mã bị hỏng. Nó dành cho những người có công cụ AI liên tục trả về lỗi không rõ nguyên nhân với các tác vụ đơn giản.
Khi nào nên dùng
- ✓Khi sandbox mã gặp lỗi không rõ nguyên nhân hoặc quá thời gian chờ.
- ✓Khi trình đọc file không mở được một file mà bạn thấy rõ là có ở đó.
- ✓Khi bạn cần đọc một file đơn giản hoặc tính toán Python ngắn để tiếp tục nhiệm vụ.
Liên kết skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/run-shell-fallback/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Trình đọc file liên tục lỗi với file notes.txt của tôi. Hãy dùng shell để đọc nó và cho tôi biết nội dung.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent dùng cat để đọc các file văn bản và dùng Python dòng lệnh qua shell để phân tích cấu trúc dữ liệu hoặc tính toán ngắn. Nó chạy các lệnh và đọc đầu ra được in ra.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Lệnh nào đọc file văn bản?
Skill dùng cat để in nội dung file trong shell.
Nó có phân tích được file JSON không?
Có, skill đưa ra một lệnh Python một dòng để tải file JSON và in nội dung.
Python dòng lệnh có an toàn cho script dài không?
Skill dùng heredoc cho script nhiều dòng, giúp mã dài dễ đọc hơn.
Chi tiết
Mô tả gốc của tác giả
Use run_shell with inline Python as a reliable fallback when execute_code_sandbox or read_file fail
repo: HKUDS/AgentPilot
Độ phổ biến
- Sao GitHub
- 7.8k
- Vị trí xếp hạng
- #12979
- Giấy phép
- MIT
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
agentpilot
7.8kGiúp agent của bạn cải thiện dự án từng bước bằng cách chuẩn bị tác vụ và chạy vòng lặp AgentPilot, gồm đề xuất, kiểm thử và chấm điểm thay đổi.
openspace
7.8kGiúp agent của bạn thiết lập OpenSpace, công cụ lưu và lấy lại skill của agent, rồi kết nối nó với ứng dụng AI của bạn qua MCP.
rsi-arena
7.8kGiúp agent của bạn thiết lập và chạy các bài kiểm thử benchmark AI chuẩn, như AIME và Terminal-Bench, để so sánh các phương pháp cải tiến khác nhau.
experiment-guide
7.8kGiúp agent của bạn lên kế hoạch các thí nghiệm nhỏ, đọc kết quả và ghi lại phát hiện khi tìm cách cải thiện một chương trình.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.