shell-python-fallback
ما الذي تفعله
تمنح هذه المهارة وكيل الذكاء الاصطناعي بديلًا لتشغيل Python عندما تعيد أدوات الكود أخطاء غير معروفة. وهي مناسبة لمن يحتاج إلى إنجاز معالجة البيانات أو إنشاء PDF بموثوقية.
متى تستخدمها
- ✓عندما تعيد أدوات الكود أخطاء غير معروفة مرتين أو أكثر في المهمة نفسها.
- ✓عندما تحتاج إلى معالجة بيانات أو تحليل ملفات أو إنشاء PDF باستخدام Python.
- ✓عندما يجب تشغيل برنامج وتريد مخرجات واضحة للتحقق منها.
رابط المهارة
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/shell-python-fallback/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“أدوات الكود تعطيني أخطاء غير معروفة في تنظيف البيانات هذا. شغّل كود Python عبر الطرفية وأرني المخرجات.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
يضمّن الوكيل برنامج Python داخل أمر في الطرفية باستخدام heredoc. ثم يشغّله، ويقرأ المخرجات المطبوعة ليتحقق من النجاح أو الأخطاء، ويعدّل الكود عند الحاجة.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من GitHub.
Shell Python Fallback
When to Use
Use this pattern when execute_code_sandbox or shell_agent tools consistently fail with "unknown error" for tasks such as:
- Data processing and transformation
- PDF generation (reportlab, etc.)
- File parsing and manipulation
- Any Python script execution that requires reliability
The Pattern
Instead of using code execution tools, embed your Python script directly in a run_shell command using a heredoc:
python3 << 'EOF'
# Your Python code here
import sys
print("Hello from embedded Python")
EOF
Step-by-Step Instructions
Identify the failure: When
execute_code_sandboxorshell_agentreturns "unknown error" repeatedly (2+ attempts), switch to this fallback.Write your Python script: Prepare the complete Python code you need to execute.
Embed in run_shell: Use
run_shellwith a heredoc syntax:
Command: python3 << 'EOF'
import json
# Your complete script here
data = {"key": "value"}
print(json.dumps(data))
EOF
Handle multi-line scripts: For longer scripts, ensure proper indentation is preserved. The heredoc preserves whitespace exactly.
Check output: Parse the stdout from
run_shellto verify success or capture errors.
Example: PDF Generation
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 World")
c.save()
print("PDF created successfully")
EOF
Example: Data Processing
python3 << 'EOF'
import csv
import json
data = []
with open('input.csv', 'r') as f:
reader = csv.DictReader(f)
for row in reader:
data.append(row)
with open('output.json', 'w') as f:
json.dump(data, f, indent=2)
print(f"Processed {len(data)} records")
EOF
Best Practices
- Quote the EOF delimiter (
<< 'EOF'not<< EOF) to prevent shell variable expansion in your Python code - Include error handling in your Python script with try/except blocks
- Print status messages to stdout so you can verify execution succeeded
- Use absolute paths or ensure working directory is correct
- Test incrementally: Start with a minimal script, then expand
Troubleshooting
| Issue | Solution |
|---|---|
| Script doesn't run | Ensure python3 is available in the shell environment |
| Indentation errors | Check that heredoc preserves spaces (use spaces, not tabs) |
| Module not found | Use python3 -m pip install <module> before running script |
| File not found | Use absolute paths or pwd to verify working directory |
Why This Works
The run_shell tool executes commands directly in the system shell, bypassing the sandbox restrictions or internal errors that affect execute_code_sandbox and shell_agent. The heredoc approach allows multi-line Python scripts while keeping everything in a single shell command.
الأسئلة الشائعة
كم عدد الإخفاقات التي تستدعي الانتقال؟
تقول المهارة إن الانتقال يكون بعد خطأين غير معروفين أو أكثر.
هل يحافظ heredoc على المسافات البادئة؟
تقول المهارة إن heredoc يحفظ المسافات بدقة، فيبقى الكود متعدد الأسطر سليمًا.
هل تستطيع إنشاء PDF؟
نعم، تقدم المهارة مثالًا لإنشاء PDF باستخدام reportlab.
التفاصيل
الوصف الأصلي من المؤلف
Use run_shell with embedded Python heredoc as reliable fallback when code execution tools fail
repo: HKUDS/AgentPilot
الشعبية
- نجوم GitHub
- 7.8k
- الترتيب
- #13001
- الترخيص
- MIT
- آخر تحديث
- 1/11/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
agentpilot
7.8kيساعد وكيلك على تحسين مشروع خطوة بخطوة، بتجهيز مهمة وتشغيل حلقة AgentPilot التي تقترح التغييرات وتختبرها وتقيّمها.
openspace
7.8kيساعد وكيلك على إعداد OpenSpace، وهو أداة تخزن مهارات الوكلاء وتسترجعها، وربطه بتطبيق الذكاء الاصطناعي عبر MCP.
rsi-arena
7.8kيساعد وكيلك على إعداد اختبارات معيارية مثل AIME وTerminal-Bench وتشغيلها، لمقارنة طرق التحسين المختلفة.
experiment-guide
7.8kيساعد وكيلك على تخطيط تجارب صغيرة وقراءة نتائجها وتسجيل ما يتعلمه أثناء التحقيق في طرق تحسين برنامج.
مهارات مشابهة
diffs
394kيتيح لوكيلك إنتاج فرق تعديلات حقيقي يمكن مشاركته، كرابط عرض أو ملف صورة، بدلاً من ملخص مكتوب يدوياً.
coding-agent
394kيساعد وكيلك على تسليم مهمة برمجة كبيرة إلى Codex أو Claude Code أو OpenCode كعامل في الخلفية، ثم متابعة تقدمها.
gh-issues
394kيساعد وكيلك على إيجاد مشكلات GitHub واختيار ما ستعمل عليه، وفتح طلبات سحب بالإصلاحات، ومتابعة تعليقات المراجعة.