Chuyển đến nội dung
Skillpedia
Lập trình chung7.8k · #12882

fallback-python-execution

Skill này làm gì

Skill này là phương pháp dự phòng để chạy Python khi sandbox hoặc agent trợ giúp không làm được. Dành cho người cần Python tạo ra tệp dữ liệu hoặc tài liệu.

Khi nào nên dùng

  • ✓Khi sandbox trả về lỗi không rõ hoặc thất bại nhiều lần.
  • ✓Khi tôi cần Python tạo bảng tính, tài liệu hoặc tệp dữ liệu.
  • ✓Khi một agent trợ giúp không thể chạy code Python đúng cách.

Liên kết skill

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

Sao 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

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/fallback-python-execution/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Trợ lý không chạy được script Python của tôi để tạo bảng tính. Hãy lưu script thành tệp và chạy trực tiếp.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI viết toàn bộ code Python vào một tệp .py, chạy bằng lệnh shell, kiểm tra các tệp mong đợi đã xuất hiện, và tùy chọn xóa script sau đó.

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.

Fallback Python Execution Pattern

When to Use

Use this pattern when:

  • execute_code_sandbox returns unknown errors or fails repeatedly
  • shell_agent cannot successfully execute Python code
  • You need to create files (spreadsheets, documents, data files) via Python
  • Direct delegated approaches prove unreliable in the current environment

Core Technique

Instead of delegating Python execution to agents, use this two-step inline approach:

  1. Write Python code to a .py file using write_file
  2. Execute the file using run_shell with python <script.py>

Step-by-Step Instructions

Step 1: Write Python Code to File

Use write_file to create a Python script with all necessary code inline:

write_file
path: /path/to/script.py
content: |
    import pandas as pd
    # Your complete Python code here
    df = pd.DataFrame({...})
    df.to_excel('output.xlsx', index=False)

Step 2: Execute via run_shell

Run the script directly:

run_shell
command: python /path/to/script.py

Step 3: Verify and Clean Up

  • Check the output for success/errors
  • Verify the expected files were created
  • Optionally remove the temporary script if no longer needed

Why This Works

This approach is more reliable because:

  • Avoids agent interpretation layers that can introduce errors
  • Provides direct control over execution environment
  • Gives clear error output for debugging
  • Bypasses sandbox delegation issues

Example: Excel File Creation

# Step 1: Write the script
write_file:
  path: create_report.py
  content: |
    import pandas as pd
    from openpyxl import Workbook
    
    # Create data
    data = {'Column1': [1, 2, 3], 'Column2': ['A', 'B', 'C']}
    df = pd.DataFrame(data)
    
    # Save to Excel
    df.to_excel('report.xlsx', index=False)
    print('Excel file created successfully')

# Step 2: Execute
run_shell:
  command: python create_report.py

Tips

  • Include error handling in your Python code for better debugging
  • Use absolute paths when possible to avoid working directory issues
  • Add print statements to track execution progress
  • Keep scripts self-contained with all imports at the top
  • For complex tasks, break into multiple scripts if needed

Troubleshooting

Issue Solution
Module not found Add pip install commands before python command
Permission errors Check file paths are writable
Script not found Use absolute path or cd to directory first
Output not created Check for Python errors in run_shell output
Câu hỏi thường gặp

Vì sao tránh agent trợ giúp?

Hướng dẫn nói cách này tránh các lớp diễn giải thêm có thể gây lỗi.

Có thể xóa script sau đó không?

Có. Xóa script tạm là bước cuối tùy chọn.

Cần kiểm tra gì ở cuối?

Đầu ra để xem thành công hay lỗi, và các tệp mong đợi có được tạo ra không.

Chi tiết

Mô tả gốc của tác giả

Reliable Python execution workflow when execute_code_sandbox or shell_agent fail

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#12882
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự