code-exec-fallback
Fallback pattern for executing Python code when execute_code_sandbox fails
适合你,如果需要在沙箱执行失败时用备用方式运行Python代码
/ 通过 npx 安装 校验哈希
npx oh-my-skill add hkuds/openspace/code-exec-fallback/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- hkuds/openspace/code-exec-fallback/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify hkuds/openspace/code-exec-fallback安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
6920GitHub stars
~520上下文体积 · 单文件
索引托管
怎么用
商店整理自技能原文 · 版本 2c5cc40 · 表述以原文为准它做什么
当沙箱执行Python代码失败时,Claude会将代码写入文件,然后通过shell命令运行该文件,并返回运行结果。
什么时候触发
当使用execute_code_sandbox执行代码连续失败(通常2次以上),原因是环境限制、超时、依赖问题或沙箱限制时触发。
装好后可以这样说
触发fallback模式。
使用write_file和run_shell。
技能原文 SKILL.md
Code Execution Fallback
When to Use
Use this pattern when execute_code_sandbox fails repeatedly (typically 2+ attempts) due to environment limitations, timeouts, dependency issues, or sandbox restrictions.
The Pattern
Instead of executing code directly in the sandbox, write the Python script to a file and execute it via shell:
- Write the script using
write_file - Execute via shell using
run_shellwithpython3 script.py - Clean up (optional) remove the temporary file
Step-by-Step Instructions
Step 1: Write the Python Script
Use write_file to save your Python code: - Path: Choose a descriptive name (e.g., "process_data.py", "analyze.py") - Content: Your complete Python script with all imports and logic
Step 2: Execute via Shell
Use run_shell to execute: - Command: "python3 <script_name>.py" - Timeout: Set appropriately for your task (default 30s, increase if needed)
Step 3: Handle Output
- Capture stdout/stderr from run_shell - Parse results as needed - Optionally delete the script file after execution
Example
# Instead of this (which may fail):
execute_code_sandbox(code="import pandas as pd; df = pd.read_csv('data.csv')...")
# Do this:
write_file(path="analyze.py", content="""
import pandas as pd
import json
df = pd.read_csv('data.csv')
result = df.groupby('category').sum()
print(json.dumps(result.to_dict()))
""")
run_shell(command="python3 analyze.py", timeout=60)
Tips for Success
- Include all imports in the script file - the shell environment may differ from the sandbox
- Use absolute paths or ensure working directory is correct
- Add error handling to your script for better debugging
- Increase timeout for long-running operations (default is 30s)
- Print structured output (JSON) if you need to parse results
- Clean up temporary files after successful execution to avoid clutter
When This Helps
- Sandbox has missing dependencies
- Code execution times out in sandbox but would work in shell
- File I/O operations are restricted in sandbox
- Need to run external commands or system utilities
- Complex multi-file projects that need proper file structure
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →
评论
登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。
…