# Code Exec Fallback

> Fallback pattern for executing Python code when execute_code_sandbox fails

- **Type:** Skill
- **Install:** `agentstack add skill-hkuds-openspace-code-exec-fallback`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [HKUDS](https://agentstack.voostack.com/s/hkuds)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [HKUDS](https://github.com/HKUDS)
- **Source:** https://github.com/HKUDS/OpenSpace/tree/main/gdpval_bench/skills/code-exec-fallback

## Install

```sh
agentstack add skill-hkuds-openspace-code-exec-fallback
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Code Execution Fallback

## When to Use

Use this pattern when `execute_code_sandbox` fails repeatedly (typically 2+ attempts) due to environment limitations, timeouts, dependency issues, or sandbox restrictions.

## The Pattern

Instead of executing code directly in the sandbox, write the Python script to a file and execute it via shell:

1. **Write the script** using `write_file`
2. **Execute via shell** using `run_shell` with `python3 script.py`
3. **Clean up** (optional) remove the temporary file

## Step-by-Step Instructions

### Step 1: Write the Python Script

```
Use write_file to save your Python code:
- Path: Choose a descriptive name (e.g., "process_data.py", "analyze.py")
- Content: Your complete Python script with all imports and logic
```

### Step 2: Execute via Shell

```
Use run_shell to execute:
- Command: "python3 .py"
- Timeout: Set appropriately for your task (default 30s, increase if needed)
```

### Step 3: Handle Output

```
- Capture stdout/stderr from run_shell
- Parse results as needed
- Optionally delete the script file after execution
```

## Example

```python
# Instead of this (which may fail):
execute_code_sandbox(code="import pandas as pd; df = pd.read_csv('data.csv')...")

# Do this:
write_file(path="analyze.py", content="""
import pandas as pd
import json

df = pd.read_csv('data.csv')
result = df.groupby('category').sum()
print(json.dumps(result.to_dict()))
""")

run_shell(command="python3 analyze.py", timeout=60)
```

## Tips for Success

1. **Include all imports** in the script file - the shell environment may differ from the sandbox
2. **Use absolute paths** or ensure working directory is correct
3. **Add error handling** to your script for better debugging
4. **Increase timeout** for long-running operations (default is 30s)
5. **Print structured output** (JSON) if you need to parse results
6. **Clean up temporary files** after successful execution to avoid clutter

## When This Helps

- Sandbox has missing dependencies
- Code execution times out in sandbox but would work in shell
- File I/O operations are restricted in sandbox
- Need to run external commands or system utilities
- Complex multi-file projects that need proper file structure

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [HKUDS](https://github.com/HKUDS)
- **Source:** [HKUDS/OpenSpace](https://github.com/HKUDS/OpenSpace)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-hkuds-openspace-code-exec-fallback
- Seller: https://agentstack.voostack.com/s/hkuds
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
