Execute code in multiple languages (Python, JavaScript, Bash) with proper session management, timeout handling, and output capture. Use this when an agent needs to run code snippets, test implementations, or execute scripts as part of task completion. Complexities: Handles subprocess management, streaming output, resource limits, and cross-platform execution (Linux/macOS/Windows).
Execute code snippets and scripts safely with proper session management and output capture.
Use this when an agent needs to:
The code execution system uses subprocess management with these key components:
agent-zero/python/tools/code_execution_tool.py - Main execution frameworkagent-zero/python/lib/subprocess_utils.py - Subprocess management utilitiesagent-zero/python/lib/session_manager.py - Session tracking and cleanup# Execute Python code
result = execute_python(
code="print('Hello, World!')",
timeout=30,
session_id="session_123"
)
# With dependencies
result = execute_python(
code="import pandas as pd; df = pd.read_csv('data.csv')",
requirements=["pandas"],
session_id="session_123"
)
# Execute Node.js code
result = execute_javascript(
code="console.log('Hello from Node.js')",
timeout=30,
session_id="session_123"
)
# Execute shell commands
result = execute_bash(
command="ls -la /tmp",
timeout=10,
session_id="session_123"
)
{
"success": True,
"output": "Hello, World!\n",
"error": "",
"exit_code": 0,
"duration_ms": 123,
"session_id": "session_123"
}
Common errors and how to handle them:
Execution hangs:
# Check for orphaned processes
ps aux | grep -E "(python|node)" | grep -v grep
# Kill specific session
kill -9 $(pgrep -f "session_123")
Output not captured:
# Ensure output is flushed
import sys
sys.stdout.flush()
Dependencies not found:
# Install manually for testing
pip install pandas
npm install lodash
After code execution:
success is True in result