‹ 首页

code-exec-fallback-266cba

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

Fallback workflow for reliable code execution when sandbox fails repeatedly

适合你,如果沙箱环境不稳定需要可靠执行代码

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

怎么用

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

当代码沙箱连续失败两次以上时,Claude会自动改用先写文件再通过shell执行的方式运行代码,并捕获输出结果。

什么时候触发

当execute_code_sandbox连续失败两次或更多,或遇到超时、环境错误等无法通过代码修复的问题时触发。

装好后可以这样说
Claude会生成脚本文件并通过shell执行。
触发回退流程,提高执行成功率。
直接使用write_file和run_shell。
技能原文 SKILL.md作者撰写 · MIT · 2c5cc40

Code Execution Fallback Pattern

When to Use This Skill

Apply this pattern when you encounter repeated failures with execute_code_sandbox:

  • 2+ consecutive failures with opaque or unknown errors
  • Timeout errors that persist across retry attempts
  • Environment-related errors that don't resolve with code fixes
The Fallback Workflow
Step 1: Detect Repeated Failures

Track execution failures. After 2 consecutive failures with execute_code_sandbox, switch to the fallback approach.

Step 2: Write Script to File

Use write_file to save your Python script:

write_file(
    path="/workspace/script_name.py",
    content="# Your Python code here\nimport sys\n..."
)
Step 3: Execute via Shell

Use run_shell to run the script:

run_shell(
    command="python /workspace/script_name.py",
    timeout=300
)
Step 4: Capture Output

Parse stdout/stderr from run_shell output to verify success or diagnose issues.

Complete Example
# Instead of this (which may fail):
result = execute_code_sandbox(code="import pandas as pd\n...")

# Use this fallback pattern:
script_content = """
import pandas as pd
import sys

try:
    # Your logic here
    df = pd.DataFrame({'col': [1, 2, 3]})
    print(df.to_csv())
    sys.exit(0)
except Exception as e:
    print(f"ERROR: {e}", file=sys.stderr)
    sys.exit(1)
"""

# Write the script
write_file(path="/workspace/my_script.py", content=script_content)

# Execute via shell
result = run_shell(command="python /workspace/my_script.py", timeout=300)
Best Practices
  1. Add error handling in your script - use try/except with sys.exit() codes
  2. Set appropriate timeouts - run_shell default is 30s, increase for heavy operations
  3. Clean up temporary files after execution if needed
  4. Log the fallback trigger - document why you switched approaches
  5. Verify Python availability - Most sandboxes have Python 3.x by default
Why This Works
  • write_file is more reliable for file I/O operations
  • run_shell gives you direct control over execution environment
  • Shell execution bypasses sandbox serialization issues
  • Better error visibility through stdout/stderr streams
When NOT to Use This Pattern
  • First-time execution failures (retry the sandbox first)
  • Simple one-liner code (sandbox is faster)
  • When sandbox errors are clearly code bugs (fix the code instead)
  • Security-sensitive operations requiring sandbox isolation
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

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