# Code Execution Fallback E81068

Fallback workflow for executing Python code when execute_code_sandbox fails repeatedly

- Repository: https://github.com/HKUDS/AgentPilot (7784 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add HKUDS/AgentPilot --skill code-execution-fallback-e81068 -g -a claude-code -y`
Codex: `npx skills add HKUDS/AgentPilot --skill code-execution-fallback-e81068 -g -a codex -y`
Cursor: `npx skills add HKUDS/AgentPilot --skill code-execution-fallback-e81068 -g -a cursor -y`
Gemini CLI: `npx skills add HKUDS/AgentPilot --skill code-execution-fallback-e81068 -g -a gemini-cli -y`

## Description

Fallback workflow for executing Python code when execute_code_sandbox fails repeatedly

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Code Execution Fallback Workflow

## When to Use

Use this skill when `execute_code_sandbox` fails repeatedly (2+ attempts) with unknown, persistent, or unexplained errors. This fallback approach uses `write_file` + `run_shell` to save Python scripts to disk and execute them via command line, which has proven more reliable in certain failure scenarios.

## Step-by-Step Instructions

### Step 1: Detect Repeated Failures

Monitor `execute_code_sandbox` attempts. After 2 consecutive failures with errors like:
- "Unknown error"
- Timeout errors
- Unexplained execution failures
- Sandbox environment issues

Switch to the fallback workflow immediately.

### Step 2: Write the Python Script to File

Use `write_file` to save your Python code as a `.py` file in the working directory:

```python
write_file(
    path="script.py",
    content="""
import sys
import json

# Your Python code here
def main():
    # Your logic
    result = {"status": "success", "data": "example"}
    print(json.dumps(result))

if __name__ == "__main__":
    main()
"""
)
```

**Tips:**
- Use clear, self-contained code that doesn't rely on sandbox-specific paths
- Include error handling and informative print statements
- Save output to files if needed for later retrieval

### Step 3: Execute via Shell

Use `run_shell` to execute the Python script via command line:

```python
run_shell(
    command="python3 script.py",
    timeout=60  # Adjust timeout as needed
)
```

**Alternative commands:**
- `python script.py` - if python3 alias isn't available
- `python3 -u script.py` - for unbuffered output
- `python3 script.py arg1 arg2` - with arguments

### Step 4: Verify Output and Results

Check the stdout/stderr from `run_shell` to:
- Confirm execution succeeded (exit code 0)
- Inspect printed output or results
- Identify any new errors (different from sandbox errors)

If the script writes output files, use `read_file` to retrieve results.

### Step 5: Clean Up (Optional)

The rest: https://github.com/HKUDS/AgentPilot/blob/HEAD/openspace/benchmarks/gdpval/skills/code-execution-fallback-e81068/SKILL.md
