Fallback method to execute Python code when execute_code_sandbox fails with e2b errors
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-sandbox-fallback-execution-048d5a-ae8689532e2f ,按照其中的说明把「sandbox-fallback-execution-048d5a」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
When execute_code_sandbox repeatedly fails with e2b sandbox errors, use this fallback pattern to execute Python code directly on the host system.
Use this skill when:
execute_code_sandbox fails with e2b-related errorsUse write_file to save your Python code as a .py file:
Tool: write_file
path: /workspace/script_name.py
content: |
# Your Python code here
import pandas as pd
# ... rest of code
Use run_shell with explicit python3 path:
Tool: run_shell
command: python3 /workspace/script_name.py
timeout: 120
Check the stdout/stderr from run_shell for:
# Instead of this (failing):
Tool: execute_code_sandbox
code: |
import pandas as pd
df = pd.DataFrame({'a': [1,2,3]})
df.to_excel('output.xlsx')
# Use this fallback:
Tool: write_file
path: /workspace/generate_report.py
content: |
import pandas as pd
# Create sample data
df = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6]})
# Save to Excel
df.to_excel('/workspace/output.xlsx', index=False)
print('File created successfully')
Tool: run_shell
command: python3 /workspace/generate_report.py
timeout: 120
E2B execution errorSandbox timeoutConnection refusedSandbox initialization failedexecute_code_sandbox retry first