मुख्य सामग्री पर जाएँ
Skillpedia
सामान्य कोडिंग7.8k · #12991

sandbox-fallback-python-e5d7ae

यह क्या करती है

यह स्किल बताती है कि जब सैंडबॉक्स शुरू या कनेक्ट न हो, तब AI एजेंट शेल से Python कोड कैसे चलाए। यह उन लोगों के लिए है जो reportlab या pandas जैसी लाइब्रेरी इस्तेमाल करते हैं।

कब इस्तेमाल करें

  • ✓जब सैंडबॉक्स इनिशियलाइज़ेशन, स्टार्टअप या कनेक्शन एरर दिखाए।
  • ✓जब एक छोटी स्क्रिप्ट को तुरंत शेल में चलाना हो।
  • ✓जब लंबी स्क्रिप्ट को फ़ाइल में सहेजकर ज़्यादा समय सीमा के साथ चलाना हो।

Skill का लिंक

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-fallback-python-e5d7ae/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/sandbox-fallback-python-e5d7ae/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“सैंडबॉक्स शुरू नहीं हो रहा। शेल में स्क्रिप्ट चलाकर reportlab से मेरा PDF इनवॉइस बनाइए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

छोटे कोड के लिए एजेंट शेल कमांड के अंदर heredoc इस्तेमाल करता है। लंबे कोड के लिए वह स्क्रिप्ट को एक अस्थायी फ़ाइल में लिखता है और चलाता है, ज़रूरत हो तो ज़्यादा समय के साथ।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Python Sandbox Fallback Pattern

When to Use

Use this pattern when execute_code_sandbox fails with e2b/sandbox initialization errors, especially when running Python code that requires external libraries like reportlab, pandas, numpy, etc.

Common Failure Indicators

Detect these error patterns to trigger the fallback:

  • e2b initialization errors
  • sandbox creation/creation timeout failures
  • container startup errors
  • Connection/refusal errors from sandbox service

The Fallback Pattern

Basic Heredoc Approach

For short scripts, use a Python heredoc directly in run_shell:

run_shell(
    command="""python3 << 'EOF'
import sys
print(f"Python version: {sys.version}")
# Your code here
EOF
""",
    timeout=60
)

File-Based Approach for Complex Scripts

For longer scripts or when you need to preserve state across multiple executions:

# Step 1: Write the script to a temporary file
script_content = '''
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
import os

# Your code here
'''

run_shell(command=f"cat > /tmp/script.py << 'SCRIPT_EOF'\n{script_content}\nSCRIPT_EOF")

# Step 2: Execute the script
result = run_shell(command="python3 /tmp/script.py", timeout=120)

Key Considerations

Timeouts

  • run_shell typically needs longer timeouts than execute_code_sandbox
  • Use timeout=60 for simple scripts
  • Use timeout=120 or higher for library-heavy operations (PDF generation, data processing)

Library Availability

  • Verify required libraries are installed in the shell environment
  • Install missing libraries first if needed:
    run_shell(command="pip install reportlab", timeout=60)
    

Error Handling

  • Capture and inspect run_shell output for Python errors
  • Check stderr for import failures or runtime exceptions

Working Directory

  • Files created via run_shell are in the current working directory by default
  • Use absolute paths or os.getcwd() to reference files reliably

Example: PDF Generation with reportlab

# FALLBACK VERSION (when execute_code_sandbox fails):

pdf_code = """
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch

def create_memo(filename):
    c = canvas.Canvas(filename, pagesize=letter)
    c.drawString(1*inch, 10*inch, "Legal Memorandum")
    c.save()
    print(f"Created {filename}")

create_memo('/workspace/output.pdf')
"""

# Write script to file
run_shell(command=f"cat > /tmp/create_pdf.py << 'PYEOF'\n{pdf_code}\nPYEOF")

# Execute and verify
run_shell(command="python3 /tmp/create_pdf.py", timeout=120)

# Verify output exists
run_shell(command="ls -la /workspace/output.pdf", timeout=30)

Comparison Table

Aspect execute_code_sandbox run_shell (fallback)
Isolation High (containerized) Low (host environment)
Reliability Can fail with e2b errors More reliable
Library Access Pre-configured sandbox Depends on host
Timeout Default 30s Configurable
File Access ARTIFACT_PATH convention Direct filesystem

Migration Checklist

When switching from execute_code_sandbox to run_shell:

  • Increase timeout values (typically 2-4x)
  • Convert ARTIFACT_PATH references to actual file paths
  • Add explicit file verification steps after execution
  • Handle potential library import errors
  • Test script execution in shell environment first
अक्सर पूछे जाने वाले सवाल

लंबी समय सीमा क्यों?

स्किल बताती है कि शेल रन को आमतौर पर सैंडबॉक्स रन से ज़्यादा समय चाहिए।

अस्थायी फ़ाइल कहाँ रखी जाती है?

स्किल का उदाहरण उसे temp फ़ोल्डर में लिखता है, हालाँकि एजेंट कोई और जगह चुन सकता है।

कौन सी लाइब्रेरी का ज़िक्र है?

यह reportlab, pandas और numpy को उन लाइब्रेरी के उदाहरण बताती है जिनकी कोड को ज़रूरत हो सकती है।

जानकारी

लेखक का मूल विवरण

Fallback to run_shell with Python heredoc when execute_code_sandbox fails

repo: HKUDS/AgentPilot

लोकप्रियता

GitHub स्टार
7.8k
रैंकिंग में स्थान
#12991
लाइसेंस
MIT
अपडेट की गई
1/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills