‹ 首页

fallback-python-execution

@hkuds · 收录于 5 天前 · 上游提交 1 周前

Reliable Python execution workflow when execute_code_sandbox or shell_agent fail

适合你,如果经常遇到代码执行环境崩溃需要兜底方案

/ 通过 npx 安装 校验哈希
npx oh-my-skill add hkuds/openspace/fallback-python-execution
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- hkuds/openspace/fallback-python-execution
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify hkuds/openspace/fallback-python-execution
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
6920GitHub stars
~557上下文体积 · 单文件
索引托管

怎么用

商店整理自技能原文 · 版本 2c5cc40 · 表述以原文为准
它做什么

当代码沙箱或代理执行 Python 失败时,安装此技能后,Claude 会改用先写 .py 文件再通过 shell 命令运行的方式,确保代码能正确执行并生成文件。

什么时候触发

当 execute_code_sandbox 重复报错、shell_agent 无法执行 Python 代码,或你需要通过 Python 创建文件时,Claude 会自动改用此模式。

装好后可以这样说
Claude 会写脚本并运行生成文件。
直接执行你提供的代码片段。
自动写入文件并运行。
技能原文 SKILL.md作者撰写 · MIT · 2c5cc40

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 |

按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。