fallback-python-shell
Skill này làm gì
Skill này chạy code Python trực tiếp từ shell để đọc tệp và xử lý dữ liệu khi các công cụ thông thường hỏng. Dành cho người cần xử lý tài liệu, bảng tính hoặc dữ liệu khi công cụ thường không chạy.
Khi nào nên dùng
- ✓Khi sandbox code trả về lỗi không rõ với một tác vụ.
- ✓Khi trình đọc tệp không đọc được tệp ở định dạng được hỗ trợ.
- ✓Khi tôi cần đọc một tệp văn bản, JSON, CSV hoặc Excel và xử lý nó.
Liên kết skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-python-shell/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 tệp thất bại với tệp dữ liệu của tôi. Hãy dùng Python trong shell để đọc và tóm tắt nội dung.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
AI chạy một script Python ngắn trong heredoc shell, mở tệp, xử lý nội dung và in kết quả trở lại cuộc trò chuyện.
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.
Shell-Based Python Fallback
When to Use
Use this fallback pattern when:
execute_code_sandboxreturns 'unknown error'read_filereturns 'unknown error' for supported formats- You need to process documents, analyze data, or read files programmatically
Core Technique
Run Python code through run_shell using a heredoc. This bypasses sandbox execution issues while maintaining Python's full capabilities for file I/O and data processing.
Basic Pattern
python3 << 'EOF'
# Your Python code here
import json
import os
# Example: Read and process a file
with open('/path/to/file.txt', 'r') as f:
content = f.read()
print(content)
EOF
Key Syntax Points
- Use
python3 << 'EOF'(quoted EOF prevents variable expansion in the heredoc) - Indent Python code starting from column 0 (no extra indentation from shell)
- End with
EOFon its own line with no leading/trailing whitespace - Print results to stdout to capture them in the tool response
Common Use Cases
Reading Files (Fallback for read_file)
python3 << 'EOF'
import json
# Read text file
with open('document.txt', 'r') as f:
content = f.read()
print(content)
# Read JSON file
with open('data.json', 'r') as f:
data = json.load(f)
print(json.dumps(data, indent=2))
EOF
Processing Excel/CSV Files
python3 << 'EOF'
import pandas as pd
# Read Excel file
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
print(df.to_string())
print(f"Shape: {df.shape}")
# Read CSV
df = pd.read_csv('data.csv')
print(df.head(10))
EOF
Reading PDF Files
python3 << 'EOF'
import fitz # PyMuPDF
doc = fitz.open('document.pdf')
for page_num in range(len(doc)):
page = doc[page_num]
text = page.get_text()
print(f"=== Page {page_num + 1} ===")
print(text)
doc.close()
EOF
Reading Word Documents
python3 << 'EOF'
from docx import Document
doc = Document('document.docx')
for para in doc.paragraphs:
print(para.text)
EOF
Data Analysis
python3 << 'EOF'
import pandas as pd
import numpy as np
df = pd.read_csv('data.csv')
# Basic statistics
print(f"Shape: {df.shape}")
print(f"Columns: {list(df.columns)}")
print(df.describe())
# Filter and aggregate
result = df.groupby('category').agg({'value': 'sum'})
print(result)
EOF
Best Practices
Error Handling: Wrap file operations in try/except blocks
python3 << 'EOF' try: with open('file.txt', 'r') as f: content = f.read() print(content) except FileNotFoundError: print("ERROR: File not found") except Exception as e: print(f"ERROR: {e}") EOFLarge Output: For large files, process in chunks or print summaries
python3 << 'EOF' with open('large_file.csv', 'r') as f: for i, line in enumerate(f): if i < 10: print(line.strip()) else: print("... truncated ...") break EOFWorking Directory: Remember run_shell executes in the current working directory. Use absolute paths or ensure you're in the right directory.
Multiple Steps: Chain related operations in a single heredoc rather than multiple calls
python3 << 'EOF' # Do all related work in one call with open('input.json') as f: data = json.load(f) processed = [transform(x) for x in data] with open('output.json', 'w') as f: json.dump(processed, f) print("Processing complete") EOF
Troubleshooting
- Module not found: Some packages may not be available. Stick to standard library or commonly pre-installed packages (pandas, numpy are often available).
- Permission errors: Ensure files aren't in protected directories.
- Character encoding: Specify encoding explicitly:
open('file.txt', 'r', encoding='utf-8') - Very long code: Split into multiple heredocs or write to a temporary .py file first.
Câu hỏi thường gặp
heredoc là gì?
Đó là cách gửi nhiều dòng code vào một lệnh shell trong một khối.
Những loại tệp nào được nhắc đến?
Hướng dẫn nhắc đến văn bản thuần, JSON, và CSV hoặc Excel được xử lý bằng pandas.
Vì sao in kết quả?
Đầu ra được in sẽ quay lại cuộc trò chuyện, nên AI có thể đọc và báo cáo.
Chi tiết
Mô tả gốc của tác giả
Use run_shell with Python heredoc when execute_code_sandbox or read_file fail
repo: HKUDS/AgentPilot
Độ phổ biến
- Sao GitHub
- 7.8k
- Vị trí xếp hạng
- #12883
- 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á.