python-heredoc-fallback
ما الذي تفعله
تُظهر هذه المهارة لوكيل الذكاء الاصطناعي كيفية تشغيل Python في الطرفية عبر heredoc عندما تتعطل بيئة الشيفرة. وهي مناسبة لمن يحتاج إلى ملفات مثل الرسوم البيانية أو مستندات Word أو جداول البيانات تُنشأ بـ Python.
متى تستخدمها
- ✓عندما تفشل بيئة الشيفرة بأخطاء إعداد أو اتصال.
- ✓عندما أحتاج إلى صورة رسم بياني أو مستند Word أو جدول بيانات تُنشأ بـ Python.
- ✓عندما تفشل مهمة إنشاء ملف في بيئة الشيفرة مرارًا.
رابط المهارة
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-heredoc-fallback/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“أنشئ رسمًا بيانيًا عموديًا من ملف input.xlsx الخاص بي واحفظه بصيغة PNG. بيئة الشيفرة تفشل باستمرار.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
يثبّت الوكيل الحزم اللازمة أولًا، ثم يشغّل شيفرة Python في الطرفية عبر heredoc. تنشئ الشيفرة الملف وتطبع رسالة عند الانتهاء.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من GitHub.
Python Heredoc Fallback for Code Execution
When to Use
Use this pattern when execute_code_sandbox fails with e2b initialization errors, sandbox connection issues, or other execution environment problems. This is especially reliable for file generation tasks.
Core Pattern
Instead of execute_code_sandbox, run Python code directly in the shell using a heredoc:
python3 << 'EOF'
# Your Python code here
import sys
print("Python code executing in shell")
EOF
Key Syntax Rules
- Use single-quoted EOF (
<< 'EOF') to prevent shell variable expansion within the Python code - No indentation before EOF - the closing delimiter must be at the start of the line
- Install packages first if needed, before the Python heredoc block
Common Use Cases
1. Matplotlib Graph Generation
python3 << 'EOF'
import matplotlib.pyplot as plt
import pandas as pd
# Load data
data = pd.read_excel('input.xlsx')
# Create visualization
plt.figure(figsize=(10, 6))
plt.plot(data['x'], data['y'])
plt.xlabel('X Label')
plt.ylabel('Y Label')
plt.title('Graph Title')
plt.savefig('output_graph.png', dpi=300, bbox_inches='tight')
plt.close()
print("Graph saved successfully")
EOF
2. Python-docx Document Creation
pip install python-docx -q
python3 << 'EOF'
from docx import Document
from docx.shared import Inches, Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH
doc = Document()
# Add title
title = doc.add_heading('Document Title', 0)
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
# Add sections
doc.add_heading('Section 1', level=1)
doc.add_paragraph('Content for section 1.')
# Add table
table = doc.add_table(rows=3, cols=3)
table.style = 'Table Grid'
# Save document
doc.save('output.docx')
print("Document created successfully")
EOF
3. General File Operations
python3 << 'EOF'
import json
import os
# Read input file
with open('input.json', 'r') as f:
data = json.load(f)
# Process data
result = {'processed': True, 'items': len(data)}
# Write output
with open('output.json', 'w') as f:
json.dump(result, f, indent=2)
print(f"Processed {result['items']} items")
EOF
Best Practices
- Install dependencies first: Run
pip install package-name -qbefore the Python block if packages aren't guaranteed to be available - Verify file paths: Files are read from and written to the current working directory
- Add print statements: Include progress/output messages to verify execution succeeded
- Close resources: Explicitly close matplotlib figures and file handles
- Handle errors gracefully: Add try/except blocks for production code
Troubleshooting
| Issue | Solution |
|---|---|
| Module not found | Add pip install <module> -q before Python block |
| File not found | Verify file exists in current directory with ls |
| Permission denied | Check file permissions and directory write access |
| Syntax errors | Ensure proper Python indentation within heredoc |
Advantages Over execute_code_sandbox
- No initialization overhead - runs immediately in existing shell
- Persistent environment - maintains state across multiple commands
- Direct file system access - no sandbox isolation issues
- Full system Python - access to all installed packages
- Reliable for large files - no sandbox size restrictions
الأسئلة الشائعة
ما أنواع الملفات التي يمكنه إنشاؤها؟
تقدم المهارة أمثلة للرسوم البيانية ومستندات Word وجداول البيانات التي تُنشأ بمكتبات Python.
هل يثبّت الوكيل الحزم؟
نعم، تطلب المهارة تثبيت أي حزم لازمة قبل تشغيل كتلة Python.
لماذا يجب أن تبدأ علامة EOF من الحافة اليسرى؟
لا تقرأ الطرفية علامة الإنهاء إلا إذا كانت في بداية السطر.
التفاصيل
الوصف الأصلي من المؤلف
Use shell Python heredoc as fallback when code sandbox fails
repo: HKUDS/AgentPilot
الشعبية
- نجوم GitHub
- 7.8k
- الترتيب
- #12960
- الترخيص
- 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 واختيار ما ستعمل عليه، وفتح طلبات سحب بالإصلاحات، ومتابعة تعليقات المراجعة.