Skillpedia
برمجة عامة7.8k · #12958

python-execution-fallback-9d4989

ما الذي تفعله

تمنح هذه المهارة وكيل الذكاء الاصطناعي طريقة احتياطية لتشغيل شيفرة Python بسيطة عندما تتعطل أداة بيئة الشيفرة. وهي مناسبة لمن تُرجع أداته أخطاء غير معروفة حتى في الشيفرة القصيرة.

متى تستخدمها

  • ✓عندما تُرجع بيئة الشيفرة خطأً غير معروف، حتى مع أمر print بسيط.
  • ✓عندما أحتاج إلى حساب سريع بـ Python وبيئة الشيفرة لا تستجيب.
  • ✓عندما أريد اختبار ما إذا كانت Python تعمل أصلًا على جهاز الذكاء الاصطناعي.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-execution-fallback-9d4989/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“بيئة الشيفرة تفشل باستمرار. من فضلك شغّل هذا الحساب بـ Python بطريقة أخرى، وأرني النتيجة.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يرسل الوكيل شيفرة Python عبر الطرفية باستخدام heredoc، فتصل الشيفرة إلى Python مباشرة. ويبدأ باختبار قصير يطبع رسالة للتأكد من توفر Python.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Python Execution Fallback

When to Use

Use this skill when execute_code_sandbox returns 'unknown error' or fails unexpectedly, even on simple Python code like print statements.

Solution

Switch to using run_shell with Python heredoc syntax instead of execute_code_sandbox.

Basic Syntax

python3 << 'EOF'
# Your Python code here
print("Hello World")
result = 2 + 2
print(f"Result: {result}")
EOF

How to Call

Instead of:

execute_code_sandbox(code="print('Hello')")

Use:

run_shell(command="python3 << 'EOF'\nprint('Hello')\nEOF")

For multi-line code, build the command string:

code = """
import json
data = {"status": "ok", "count": 42}
print(json.dumps(data))
"""
run_shell(command=f"python3 << 'EOF'\n{code}\nEOF")

Why This Works

  • run_shell executes commands directly in the shell environment, bypassing sandbox issues
  • Heredoc syntax (<< 'EOF') allows clean multi-line Python code without complex escaping
  • Single quotes around EOF prevent unwanted shell variable expansion
  • More reliable for simple to moderate Python execution tasks

Guidelines

  1. Always use single quotes around EOF ('EOF') to prevent variable expansion
  2. Test with a simple print statement first to verify Python is available
  3. For longer scripts, consider writing to a .py file first, then executing:
    run_shell(command="python3 /path/to/script.py")
    
  4. Capture stdout from run_shell to get Python output
  5. Handle errors by checking run_shell's stderr output

Example: Complete Workflow

# Step 1: Try execute_code_sandbox
try:
    result = execute_code_sandbox(code="print(2+2)")
except Exception as e:
    # Step 2: Fallback to run_shell with heredoc
    result = run_shell(command="python3 << 'EOF'\nprint(2+2)\nEOF")
    # Parse stdout to get the output
    output = result.stdout.strip()

Troubleshooting

Issue Solution
Python not found Use which python3 to verify installation
Heredoc not working Ensure single quotes around EOF delimiter
Complex imports fail Install required packages or write to .py file
Output not captured Check run_shell stdout, not return value
الأسئلة الشائعة

ما هو heredoc؟

طريقة لتمرير عدة أسطر من الشيفرة إلى برنامج بأمر واحد دون حفظها أولًا.

هل أستخدمها للسكربتات الطويلة؟

تقترح المهارة حفظ السكربتات الطويلة في ملف أولًا ثم تشغيله.

لماذا نستخدم علامات اقتباس مفردة حول EOF؟

علامات الاقتباس المفردة تمنع الطرفية من تغيير علامات الدولار أو الرموز الأخرى داخل الشيفرة.

التفاصيل

الوصف الأصلي من المؤلف

Fallback method for executing Python when execute_code_sandbox fails with unknown errors

repo: HKUDS/AgentPilot

الشعبية

نجوم GitHub
7.8k
الترتيب
#12958
الترخيص
MIT
آخر تحديث
1‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة