‹ 首页

fallback-script-execution

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

Two-step script execution workflow for debugging when shell_agent and execute_code_sandbox consistently fail

适合你,如果常用shell或沙箱执行脚本但偶尔遇到执行失败的情况

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

怎么用

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

当常规执行方式反复失败时,Claude 会先将脚本写入文件,再用 run_shell 执行,从而获得更清晰的错误信息和更好的调试能力。

什么时候触发

当 shell_agent 或 execute_code_sandbox 持续出错、超时,或你需要调试内联代码时触发。

装好后可以这样说
执行两步调试流程
手动触发文件执行步骤
适用于数据脚本调试
技能原文 SKILL.md作者撰写 · MIT · 2c5cc40

Fallback Script Execution with write_file + run_shell

When to Use This Skill

Use this pattern when:

  • shell_agent fails repeatedly with unclear error messages
  • execute_code_sandbox consistently errors or times out
  • You need better visibility into what's happening during execution
  • Debugging inline code or delegated agents proves difficult
Core Pattern

Instead of delegating execution to an agent or running inline code, use this two-step approach:

  1. Write script to file using write_file
  2. Execute script using run_shell with python script.py

This provides:

  • Clearer error messages (full stack traces visible in run_shell output)
  • Easier debugging (script persists for inspection)
  • Better control over execution environment
  • Ability to modify and re-run without rewriting code
Step-by-Step Instructions
Step 1: Write the Script File

Use write_file to create a self-contained Python script:

write_file with:
  path: "path/to/script_name.py"
  content: |
    #!/usr/bin/env python3
    # Your complete script here
    # Include imports, logic, and error handling

Best Practices:

  • Include descriptive comments
  • Add try/except blocks for error handling
  • Print intermediate results for debugging
  • Use absolute or clear relative paths
Step 2: Execute the Script

Use run_shell to execute the script:

run_shell with:
  command: "python path/to/script_name.py"

Best Practices:

  • Capture and examine full output
  • If errors occur, the script file is still available for inspection
  • You can re-run with modifications without starting over
Example: Data Processing Task
❌ Problematic Approach (shell_agent fails repeatedly)
shell_agent with:
  task: "Load Excel file, calculate correlations, save results"

Result: Agent struggles with path handling, unclear errors

✅ Recommended Approach (write_file + run_shell)
# Step 1: Write script
write_file with:
  path: "correlation_analysis.py"
  content: |
    import pandas as pd
    import sys
    
    try:
        # Load data
        df = pd.read_excel('data.xlsx', sheet_name='Returns')
        print(f"Loaded {len(df)} rows")
        
        # Calculate correlation
        corr = df.corr()
        print(f"Correlation matrix shape: {corr.shape}")
        
        # Save results
        with pd.ExcelWriter('output.xlsx') as writer:
            df.to_excel(writer, sheet_name='Returns')
            corr.to_excel(writer, sheet_name='Correlation')
        
        print("SUCCESS: output.xlsx created")
    except Exception as e:
        print(f"ERROR: {type(e).__name__}: {e}", file=sys.stderr)
        sys.exit(1)

# Step 2: Execute script
run_shell with:
  command: "python correlation_analysis.py"
Debugging Tips
  1. Add print statements at key points to trace execution
  2. Check file paths - use run_shell with ls -la path/ to verify files exist
  3. Inspect errors - run_shell output shows full Python stack traces
  4. Modify and re-run - edit the script file and execute again without rewriting
When to Escalate

If this pattern also fails:

  • Verify Python is available: run_shell with which python or python --version
  • Check file permissions: run_shell with ls -la script.py
  • Try explicit Python path: run_shell with /usr/bin/python script.py
  • Consider task complexity - may need to break into smaller scripts
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

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