shell-python-heredoc
यह क्या करती है
यह स्किल AI एजेंट को दिखाती है कि सैंडबॉक्स बार-बार विफल होने पर बहु-पंक्ति Python स्क्रिप्ट शेल से कैसे चलाएँ। यह उन लोगों के लिए है जिनकी स्क्रिप्ट में कई इम्पोर्ट हैं या जिन्हें साफ़ एरर आउटपुट चाहिए।
कब इस्तेमाल करें
- ✓जब कोड सैंडबॉक्स बिना समझ आए कारणों से दो या अधिक बार विफल हो।
- ✓जब स्क्रिप्ट में reportlab या pandas जैसे कई इम्पोर्ट हों और वह एक पंक्ति के लिए बहुत लंबी हो।
- ✓जब आपको stdout और stderr दिखने चाहिए ताकि पता चले क्या गलत हुआ।
Skill का लिंक
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/shell-python-heredoc/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“सैंडबॉक्स दो बार विफल होने के कारण मेरी बहु-पंक्ति ReportLab स्क्रिप्ट शेल से चलाइए। आउटपुट दिखाइए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट स्क्रिप्ट को एक उद्धृत समाप्ति मार्कर वाले heredoc में लपेटता है और समय सीमा के साथ python3 से चलाता है। फिर वह stdout और stderr पढ़कर देखता है कि काम हुआ या नहीं।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Shell Python Heredoc (Fallback Pattern)
Overview
When execute_code_sandbox fails repeatedly (e.g., with "unknown error"), use run_shell with a Python heredoc as a reliable fallback for executing multi-line Python scripts with imports.
When to Use
execute_code_sandboxhas failed 2+ times with unexplained errors- You need to run Python code with multiple imports (e.g., ReportLab, pandas)
- The script is too complex for a one-liner but doesn't require persistence between calls
- You need better error visibility from raw stdout/stderr
How to Use
Basic Pattern
run_shell(
command="""python3 << 'EOF'
import sys
# Your Python code here
print("Hello from heredoc")
EOF""",
timeout=300
)
Key Syntax Rules
- Use
<< 'EOF'(with single quotes) to prevent shell variable expansion - Indent Python code relative to the heredoc delimiter
- End with
EOFon its own line (no leading whitespace) - Capture output from stdout/stderr for debugging
Example: Generating a PDF with ReportLab
run_shell(
command="""python3 << 'EOF'
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas("output.pdf", pagesize=letter)
c.drawString(100, 750, "Hello PDF")
c.save()
print("PDF created successfully")
EOF""",
timeout=300
)
Example: Multi-file Data Processing
run_shell(
command="""python3 << 'EOF'
import pandas as pd
import json
# Load and process data
df = pd.read_csv("data.csv")
summary = df.describe()
# Output results
print(summary.to_string())
with open("summary.json", "w") as f:
json.dump(summary.to_dict(), f)
print("Processing complete")
EOF""",
timeout=300
)
Advantages Over execute_code_sandbox
- More reliable for complex imports (no sandbox isolation issues)
- Full stdout/stderr access for debugging
- Longer timeout flexibility (60s default vs 30s)
- Direct filesystem access without ARTIFACT_PATH indirection
Disadvantages
- No persistent state between calls (each heredoc is a fresh process)
- Verbose for simple one-liners
- Shell escaping may be needed for complex string literals
Troubleshooting
| Issue | Solution |
|---|---|
EOF not recognized |
Ensure EOF is on its own line with no leading spaces |
| Import errors | Verify packages are installed in the shell environment |
| File not found | Use absolute paths or check working directory with pwd |
| Syntax errors | Check Python indentation within heredoc |
See Also
- Use
execute_code_sandboxfor simpler scripts when available - Use
shell_agentfor tasks requiring autonomous iteration and error recovery - Consider writing scripts to
.pyfiles for complex, reusable code
अक्सर पूछे जाने वाले सवाल
समाप्ति मार्कर पंक्ति की शुरुआत में क्यों होना चाहिए?
शेल समाप्ति मार्कर तभी पहचानता है जब उसके आगे खाली जगह न हो।
उद्धृत मार्कर क्यों इस्तेमाल करें?
उद्धृत मार्कर शेल को Python कोड के अंदर वेरिएबल या प्रतीक बदलने से रोकता है।
क्या स्क्रिप्ट कॉल के बीच स्थिति याद रखती है?
स्किल कहती है कि यह तरीका उन कामों के लिए है जिन्हें कॉल के बीच स्थिति रखने की ज़रूरत नहीं होती।
जानकारी
लेखक का मूल विवरण
Execute complex Python code via run_shell heredoc when execute_code_sandbox fails
repo: HKUDS/AgentPilot
लोकप्रियता
- GitHub स्टार
- 7.8k
- रैंकिंग में स्थान
- #13002
- लाइसेंस
- MIT
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
agentpilot
7.8kआपके एजेंट को AgentPilot से प्रोजेक्ट को चरण-दर-चरण सुधारने में मदद करती है, जिसमें बदलाव सुझाए, परखे और स्कोर किए जाते हैं।
openspace
7.8kआपके एजेंट को OpenSpace सेट करने में मदद करती है, जो एजेंट स्किल्स सहेजता और वापस लाता है, और MCP के ज़रिए आपके AI ऐप से जुड़ता है।
rsi-arena
7.8kआपके एजेंट को AIME और Terminal-Bench जैसे मानक AI बेंचमार्क टेस्ट सेट करने और चलाने में मदद करती है, ताकि सुधार के तरीकों की तुलना हो सके।
experiment-guide
7.8kआपके एजेंट को छोटे प्रयोग बनाने, उनके नतीजे पढ़ने और जाँच के दौरान उपयोगी निष्कर्ष लिखने में मदद करती है।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।