Code Execution Tool Languages in Agent Zero: Python and Node.js Support
The code_execution_tool in Agent Zero supports Python (via IPython) and JavaScript (via Node.js), alongside shell command execution through terminal sessions.
The code_execution_tool is a core component of the agent0ai/agent-zero framework that enables AI agents to execute arbitrary code safely within sandboxed environments. Understanding which programming languages are available helps developers design effective agent workflows that leverage the right runtime for specific automation tasks.
Supported Programming Languages
The CodeExecution class in python/tools/code_execution_tool.py explicitly handles two programming language runtimes through dedicated execution paths.
Python Runtime
When you specify runtime="python", the tool executes code using IPython in a persistent session. According to the source code in [code_execution_tool.py](https://github.com/agent0ai/agent-zero/blob/main/python/tools/code_execution_tool.py#L69-L73), the implementation builds the command ipython -c <code> within the execute_python_code method (lines 63-67). This approach provides enhanced interactive features compared to standard Python interpreters while maintaining session state across multiple calls.
Node.js Runtime
For JavaScript execution, setting runtime="nodejs" triggers the Node.js runtime. The source code shows this handled in the elif runtime == "nodejs": … branch (lines 74-77) of [code_execution_tool.py](https://github.com/agent0ai/agent-zero/blob/main/python/tools/code_execution_tool.py#L74-L77). The tool constructs the command node /exe/node_eval.js <code> through the execute_nodejs_code function, allowing agents to run modern JavaScript including ES6+ features.
Additional Runtime Modes
Beyond programming languages, the code_execution_tool supports three additional operational modes that manage execution context:
runtime="terminal": Executes arbitrary shell commands (bash on Linux/macOS, PowerShell on Windows) through the interactive shell helpers defined inpython/helpers/shell_local.pyandpython/helpers/shell_ssh.pyruntime="output": Retrieves the most recent output from an active session without sending new coderuntime="reset": Clears and resets the specified session, clearing all variables and imports
These modes are implemented in the conditional branches starting at lines 77-80 of the main tool file, though they do not constitute language runtimes themselves.
Implementation Details in agent-zero Source Code
The runtime selection logic resides in the execute method of the CodeExecution class. The dispatcher uses simple string matching against the runtime parameter:
python: Callsexecute_python_code(lines 63-67)nodejs: Callsexecute_nodejs_code(lines 69-73)terminal: Callsexecute_terminal_command(lines 77-80)
Related infrastructure includes:
python/tools/input.py: Wraps user keyboard input forwarding to terminal sessionspython/helpers/shell_local.py: Provides local interactive shell managementpython/helpers/shell_ssh.py: Enables remote execution whencode_exec_ssh_enabledis configured
Practical Usage Examples
The following examples demonstrate how to invoke each supported language runtime through the Agent Zero framework:
Executing Python Code
# Build the arguments for the tool
args = {
"runtime": "python", # tells CodeExecution to run Python
"code": "print('Hello from Python!')",
"session": 0, # use the default session
"allow_running": False,
}
# Initialise and run the tool (normally done by the Agent framework)
cet = CodeExecution(agent, "code_execution_tool", "", args, message, loop_data)
response = await cet.execute(**args)
print(response.message) # → Hello from Python!
Executing JavaScript (Node.js) Code
args = {
"runtime": "nodejs",
"code": "console.log('Hello from Node.js!');",
"session": 1,
"allow_running": False,
}
cet = CodeExecution(agent, "code_execution_tool", "", args, message, loop_data)
response = await cet.execute(**args)
print(response.message) # → Hello from Node.js!
Running Terminal Commands
args = {
"runtime": "terminal",
"code": "ls -la", # any shell command
"session": 0,
"allow_running": True, # allow sending while a session is already running
}
cet = CodeExecution(agent, "code_execution_tool", "", args, message, loop_data)
response = await cet.execute(**args)
print(response.message) # ← directory listing
Summary
- The
code_execution_toolin Agent Zero supports Python (via IPython) and JavaScript (via Node.js) as primary programming languages. - Python execution uses the
ipython -ccommand structure inexecute_python_code(lines 63-67 ofcode_execution_tool.py). - Node.js execution invokes
node /exe/node_eval.jsthroughexecute_nodejs_code(lines 69-73). - Additional
runtimevalues include"terminal"for shell commands,"output"for retrieval, and"reset"for session management. - Implementation spans
python/tools/code_execution_tool.pywith shell helpers inpython/helpers/shell_local.pyandpython/helpers/shell_ssh.py.
Frequently Asked Questions
Does code_execution_tool support languages other than Python and JavaScript?
No. As implemented in python/tools/code_execution_tool.py, the tool only recognizes python and nodejs as language runtimes. While you can execute code in other languages indirectly through the terminal runtime by invoking their compilers or interpreters (e.g., gcc for C or rustc for Rust), native support is limited to Python and Node.js.
How does the tool execute Python code internally?
The tool invokes IPython rather than the standard Python interpreter. In the execute_python_code method (lines 63-67), it constructs the command ipython -c <code> which provides enhanced introspection, magics, and interactive features. The session parameter maintains state across multiple executions, preserving variables and imports between calls.
Can I run shell commands with code_execution_tool?
Yes. By setting runtime="terminal", you can execute arbitrary shell commands including bash scripts, system utilities, or package managers. The tool interfaces with python/helpers/shell_local.py for local execution or python/helpers/shell_ssh.py for remote SSH-based shells when the code_exec_ssh_enabled configuration flag is active.
What is the difference between runtime="python" and runtime="terminal"?
When using runtime="python", the tool specifically invokes IPython with your code as the -c argument, capturing stdout/stderr within the Python process. With runtime="terminal", your code is sent to an interactive system shell (bash/PowerShell) as raw text, allowing multi-line scripts, piping, and access to system binaries, but without Python-specific session management.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →