mirror of
https://github.com/MervinPraison/PraisonAIUI.git
synced 2026-11-08 08:11:08 -10:00
Added comprehensive details for new feature endpoints including memory context retrieval, TTS functionalities, marketplace actions, code execution, PWA enhancements, and device pairing capabilities.
2.2 KiB
2.2 KiB
Code Execution
Sandboxed code execution with language allowlists and SDK integration. Wraps praisonaiagents.tools.code.execute_code when available, falls back to safe simulation mode.
Quick Start
# List supported languages
curl http://localhost:8083/api/code/languages
# Execute code
curl -X POST http://localhost:8083/api/code/execute \
-H "Content-Type: application/json" \
-d '{"code":"print(\"Hello World\")","language":"python"}'
How It Works
graph TD
A["Code Submission"] --> B{"SandboxExecutionManager"}
B --> C{"SDK Available?"}
C -->|Yes| D["praisonaiagents\nexecute_code()"]
C -->|No| E["Simulated Mode\n(safe, no execution)"]
B --> F{"Language Allowed?"}
F -->|No| G["400 Error\n+ allowed list"]
- Code is submitted with a target language
- The manager checks if the language is in the allowlist (default: python, javascript, bash)
- If
praisonaiagentsis installed, delegates toexecute_codefor real execution - Otherwise returns a simulation response with the code size
Configuration
from praisonaiui.features.code_execution import SandboxExecutionManager, set_execution_manager
# Custom configuration
mgr = SandboxExecutionManager(
sandbox=True, # Enable sandbox mode
timeout=60, # Execution timeout
allowed_languages=["python", "javascript"] # Only allow these languages
)
set_execution_manager(mgr)
REST API
| Endpoint | Method | Description |
|---|---|---|
/api/code/languages |
GET | List supported languages |
/api/code/execute |
POST | Execute code in sandbox |
POST /api/code/execute
// Request
{"code": "print('hello')", "language": "python", "timeout": 30}
// Response (simulated mode)
{"language": "python", "status": "simulated",
"output": "[Sandbox] Code received (15 chars, python)",
"sandbox": true, "note": "Install praisonaiagents for real execution"}
// Response (disallowed language → 400)
{"status": "error", "error": "Language 'ruby' not allowed",
"allowed": ["python", "bash", "javascript"]}
Related
- Skills — Code execution tools in the skill catalog