OpenSpace fallback-code-execution
Fallback workflow for running code via file write and shell when sandbox execution fails
install
source · Clone the upstream repo
git clone https://github.com/HKUDS/OpenSpace
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HKUDS/OpenSpace "$T" && mkdir -p ~/.claude/skills && cp -r "$T/gdpval_bench/skills/fallback-code-execution" ~/.claude/skills/hkuds-openspace-fallback-code-execution && rm -rf "$T"
manifest:
gdpval_bench/skills/fallback-code-execution/SKILL.mdsource content
Fallback Code Execution Workflow
Overview
This skill defines a robust workaround for executing code (specifically Python) when the primary
execute_code_sandbox tool fails repeatedly with unknown or transient errors. Instead of continuing to retry the failing tool, the agent switches to a manual file-write and shell-execution pattern.
Trigger Conditions
Activate this workflow when:
fails 2 or more times consecutively for the same logic.execute_code_sandbox- Error messages are generic, unknown, or indicate environment issues rather than syntax errors.
- The code logic itself is verified correct but the execution environment is unstable.
Procedure
Step 1: Write Script to File
Use the
write_file tool to save the Python script to a specific path in the workspace.
- Path: Choose a descriptive name ending in
(e.g.,.py
).scripts/generate_report.py - Content: Ensure the script includes necessary error handling and print statements for debugging.
- Dependencies: If the script requires external libraries, ensure a
is updated or installed via shell beforehand.requirements.txt
Example:
tool: write_file path: workspace/scripts/process_data.py content: | import sys # ... script logic ... print("Success")
Step 2: Execute via Shell
Use the
run_shell tool to execute the script using the system Python interpreter.
- Command:
orpython3 <path_to_script>
.python <path_to_script> - Working Directory: Ensure the shell command runs from the workspace root or the directory containing the script.
- Capture Output: Store stdout and stderr for verification.
Example:
tool: run_shell command: python3 scripts/process_data.py
Step 3: Verify Execution
- Check Exit Code: Ensure the shell command returned exit code
.0 - Check Output: Verify expected files were created or expected stdout messages appeared.
- Handle Errors: If the shell execution fails, inspect the stderr output. This often provides more detailed tracebacks than the sandbox tool.
Best Practices
- Absolute Paths: When writing scripts that access files, use absolute paths or resolve paths relative to
to avoid working directory issues.__file__ - Permissions: Ensure the workspace directory allows file creation and execution.
- Cleanup: Optionally remove temporary scripts after successful execution if cleanliness is required.
- Logging: Add explicit
statements in the Python script to log progress, as shell output capture is sometimes more reliable than sandbox return values.print()
Example Scenario
Problem:
execute_code_sandbox times out while generating a PDF.
Solution:
- Write
togenerate_pdf.py
.workspace/scripts/ - Run
viapython3 workspace/scripts/generate_pdf.py
.run_shell - Confirm
exists in the workspace.output.pdf