Pular para o conteúdo
Skillpedia
Código em geral7,8 mil · #12847

code-execution-fallback

O que ela faz

Esta skill cobre a verificação da pasta de trabalho antes de o código rodar e a alternativa de execução pelo shell quando necessário. Ela é para quem roda scripts escritos por IA e encontra arquivos salvos no lugar errado.

Quando usar

  • ✓Quando arquivos continuam aparecendo na pasta errada durante uma tarefa de IA.
  • ✓Quando o sandbox falha repetidamente e uma versão mais simples do código não resolve.
  • ✓Quando quero que a IA rode Python pelo shell, com o código escrito na própria linha de comando.

Link da skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/code-execution-fallback/SKILL.md

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/code-execution-fallback/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Minha IA continua salvando arquivos no lugar errado e o sandbox continua falhando. Corrija a pasta e rode o script pelo shell.”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

A IA verifica primeiro a pasta de trabalho, tenta um código mais simples e depois passa para uma execução pelo shell com o código escrito em linha. Confere a saída para confirmar que a execução deu certo.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do GitHub.

Code Execution Fallback & Workspace Anchoring

This skill provides a robust pattern for executing code when the primary method fails, combined with proper workspace path management to prevent file location errors.

Core Techniques

1. Workspace Path Anchoring

Always establish and verify your working directory at the start of any task:

# At the beginning of any code execution
import os
workspace_path = os.getcwd()
print(f"Working directory: {workspace_path}")
# In shell scripts
pwd
echo "Current directory: $(pwd)"

Why: Prevents files from being written to unexpected locations when agents switch between tools.

2. Execution Fallback Ladder

When execute_code_sandbox fails, follow this escalation pattern:

Level 1: Retry with Simpler Code

  • Simplify the code structure
  • Remove complex dependencies
  • Add explicit error handling

Level 2: Use run_shell with Heredoc

When sandbox execution repeatedly fails, switch to shell execution:

python3 << 'EOF'
import os
import pandas as pd

# Your code here
data = {"col1": [1, 2, 3], "col2": ["a", "b", "c"]}
df = pd.DataFrame(data)
df.to_csv("output.csv", index=False)
print("File written successfully")
EOF

Key points:

  • Use << 'EOF' (quoted) to prevent variable expansion
  • Include all imports and dependencies inline
  • Add explicit success/failure messages

Level 3: Delegate to shell_agent

For complex multi-step tasks with error recovery needs:

Task: Create a data processing pipeline that reads CSV, transforms data, and outputs Excel
Requirements:
- Handle missing values
- Apply transformations
- Write to ./output/ directory
- Retry on transient errors

3. Explicit Path Management

Always use absolute or explicitly relative paths:

# BAD - relies on implicit working directory
df.to_csv("output/data.csv")

# GOOD - explicit path anchoring
import os
base_path = os.getcwd()
output_dir = os.path.join(base_path, "output")
os.makedirs(output_dir, exist_ok=True)
df.to_csv(os.path.join(output_dir, "data.csv"))
# BAD
cd some_dir && python script.py

# GOOD
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
python script.py

Decision Tree

execute_code_sandbox fails?
├── Yes, with syntax/import errors → Fix code, retry Level 1
├── Yes, with timeout/resource errors → Use Level 2 (run_shell heredoc)
├── Yes, with unknown/unclear errors → Use Level 3 (shell_agent)
└── No, success → Verify output file exists at expected path

Common Failure Scenarios & Solutions

Error Type Likely Cause Recommended Fallback
ModuleNotFoundError Missing packages run_shell with pip install first
Timeout Long-running operation shell_agent with progress tracking
PermissionError Wrong directory Verify workspace path, use explicit paths
Unknown error Sandbox limitations run_shell or shell_agent

Example: Robust File Generation

# Step 1: Anchor workspace
import os
workspace = os.getcwd()
print(f"Workspace: {workspace}")

# Step 2: Create output directory explicitly
output_path = os.path.join(workspace, "deliverables")
os.makedirs(output_path, exist_ok=True)

# Step 3: Generate content with error handling
try:
    # Your generation logic here
    with open(os.path.join(output_path, "report.txt"), "w") as f:
        f.write("Content here")
    print(f"Success: File written to {output_path}")
except Exception as e:
    print(f"Error: {e}")
    # Signal to escalate to run_shell or shell_agent
    raise

Anti-Patterns to Avoid

  • ❌ Assuming current directory without verification
  • ❌ Using relative paths like ../output/file.txt without context
  • ❌ Repeatedly retrying failed execute_code_sandbox without changing approach
  • ❌ Not checking if output files exist after generation
  • ❌ Mixing implicit and explicit path styles in same task

Verification Checklist

After any code execution:

  • Confirm working directory was verified at start
  • Confirm output files exist at expected paths
  • Confirm file contents are non-empty and valid
  • If execution failed, escalate to next fallback level within 2 retries
Perguntas frequentes

O que é uma execução inline pelo shell?

É passar várias linhas de Python para um comando de shell em um único bloco, em vez de usar o sandbox.

Por que verificar a pasta de trabalho primeiro?

Isso evita que arquivos sejam gravados em lugares inesperados quando a IA troca de ferramenta.

O que vem antes da troca para o shell?

O guia sugere tentar primeiro um código mais simples e só então mudar para a execução pelo shell se ainda assim falhar.

Detalhes

Descrição original do autor

Handle code execution failures with fallback strategies and anchored workspace paths

repo: HKUDS/AgentPilot

Popularidade

Estrelas no GitHub
7,8 mil
Posição no ranking
#12847
Licença
MIT
Atualizada em
01/11/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas