code-exec-fallback-266cba
Fallback workflow for reliable code execution when sandbox fails repeatedly
- License 许可
- MIT
- 所属仓库
- AG064/OpenSpace
- 最近更新
- 2026-10-08
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- code-exec-fallback-266cba
- description
- Fallback workflow for reliable code execution when sandbox fails repeatedly
02 资源文件 1
- 其他.skill_id39 B
03 SKILL.md 正文
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
- Add error handling in your script - use try/except with
sys.exit()codes - Set appropriate timeouts -
run_shelldefault is 30s, increase for heavy operations - Clean up temporary files after execution if needed
- Log the fallback trigger - document why you switched approaches
- Verify Python availability - Most sandboxes have Python 3.x by default
Why This Works
write_fileis more reliable for file I/O operationsrun_shellgives 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
04 同仓库更多 Skills
write-special-chars-ts-check
Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, plus a reliable TypeScript type-checking step that filters output to only the newly-written files to avoid being misled by pre-existing errors.
write-special-chars-readback
Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, with mandatory post-write verification via read_file and cleanup of /tmp helper scripts.
write-special-chars-heredoc
Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) by using a Python heredoc script executed via shell.
worldmonitor-reference
Curated architecture index of the WorldMonitor open-source dashboard. Reference for extracting patterns — vanilla TypeScript, Panel class hierarchy, service layer, CSS grid, API edge functions, refresh scheduler, and 60+ data source integrations.
virtual-list
Implement efficient virtual scrolling for rendering large lists with DOM recycling, chunk-based rendering, and performance optimizations
verify-directory-structure
Diagnose and resolve file access issues by first verifying the directory structure.