Execute code safely and flexibly with CAMEL’s suite of interpreters: local, isolated, and cloud-based execution environments.
Interpreters allow CAMEL agents to execute code snippets in various secure and flexible environments—from local safe execution to isolated Docker containers and managed cloud sandboxes.
Interpreters empower agents to run code dynamically—enabling evaluation,
testing, task automation, and rich feedback loops. Choose your interpreter
based on trust, isolation, and supported languages.
Internal Python Interpreter
Fast, local, safe execution for trusted Python code within the agent
process.
Subprocess Interpreter
Isolated execution in a subprocess. Supports Bash, Python, shell
scripts.
Fast, local, and safe—executes trusted Python code directly within the CAMEL agent process. Note: Only expressions (not statements) are allowed in strict safe mode; for output, your code should evaluate to a string.
Copy
from camel.interpreters import InternalPythonInterpreter# Initialize the interpreterinterpreter = InternalPythonInterpreter()# Code to execute (should evaluate to a string)python_code = "'Hello from InternalPythonInterpreter!'"# Run coderesult_str = interpreter.run(code=python_code, code_type="python")print(f"Result: {result_str}")
Subprocess Interpreter
Execute shell commands or scripts in a separate process for isolation and flexibility.
Supports multiple languages, including Bash and Python.
Copy
from camel.interpreters import SubprocessInterpreterinterpreter = SubprocessInterpreter()shell_command = "echo 'Hello from SubprocessInterpreter!'"result_str = interpreter.run(code=shell_command, code_type="bash")print(f"Result: {result_str.strip()}")
Docker Interpreter
Provides full isolation—code runs in a Docker container, protecting your host system and supporting any dependencies. Requires Docker installed. Install Docker
Copy
from camel.interpreters import DockerInterpreterinterpreter = DockerInterpreter()python_code_in_docker = "print('Hello from DockerInterpreter!')"result_str = interpreter.run(code=python_code_in_docker, code_type="python")print(f"Result: {result_str.strip()}")
IPython Interpreter (JupyterKernel)
Interactive, stateful execution in a Jupyter-like Python kernel—maintains session state and supports rich outputs.
Copy
from camel.interpreters import JupyterKernelInterpreterinterpreter = JupyterKernelInterpreter( require_confirm=False, print_stdout=True, print_stderr=True)python_code_in_jupyter_kernel = "print('Hello from JupyterKernelInterpreter!')"result = interpreter.run(code=python_code_in_jupyter_kernel, code_type="python")print(result)
E2B Interpreter (Cloud Sandbox)
Run code in a secure, scalable, cloud-based environment—no local setup needed, great for running untrusted or complex code. E2B Documentation
Copy
from camel.interpreters import E2BInterpreterinterpreter = E2BInterpreter()python_code_in_e2b = "print('Hello from E2BInterpreter!')"result = interpreter.run(code=python_code_in_e2b, code_type="python")print(result)
Best Practices
Use InternalPythonInterpreter only for trusted and simple Python code.
Subprocess and Docker interpreters are better for code isolation and dependency management.
Prefer Docker for any untrusted code or when extra libraries are needed.
E2B Interpreter is ideal for scalable, managed, and safe cloud execution—no local risk.
For interactive, multi-step logic, leverage JupyterKernelInterpreter for persistent session state.
Always validate and sanitize user inputs if agents dynamically construct code for execution.
Troubleshooting & Tips
If Docker isn’t working, verify your Docker daemon is running and you have the correct permissions.
For E2B, check API key and account limits if code doesn’t execute.
Long-running scripts are best managed in Subprocess or Docker interpreters with timeout controls.
Use session resets (where supported) to avoid cross-task state bleed in Jupyter/IPython interpreters.