đ« CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
title: "Interpreters" description: "Execute code safely and flexibly with CAMELâs suite of interpreters: local, isolated, and cloud-based execution environments." icon: terminal
doc_code_map: - "camel/interpreters/**/*.py"
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.
What are Interpreters?
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.{" "}
Fast, local, safe execution for trusted Python code within the agent
process.
Best for: Trusted code, quick Python evaluation.
{" "}
Isolated execution in a subprocess. Supports Bash, Python, shell
scripts.
Best for: Shell commands, scripts, process isolation.
{" "}
Fully sandboxed in Docker containers.
Best for: Untrusted code, dependency isolation, safe experimentation.
Install Docker
{" "}
Interactive, stateful execution via Jupyter/IPython kernel.
Best for: Multi-step reasoning, persistent variables, rich outputs.
{" "}
Cloud-based sandboxing for scalable, secure remote execution.
Best for: Managed, scalable tasks. No local setup needed.
E2B Docs
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.
```python from camel.interpreters import InternalPythonInterpreter
Initialize the interpreter
interpreter = InternalPythonInterpreter()
Code to execute (should evaluate to a string)
python_code = "'Hello from InternalPythonInterpreter!'"
Run code
result_str = interpreter.run(code=python_code, code_type="python") print(f"Result: {result_str}")
</Card>
<Card icon="code" title="Subprocess Interpreter" className="my-6">
Execute shell commands or scripts in a separate process for isolation and flexibility.<br/>
Supports multiple languages, including Bash and Python.
<br/><br/>
```python
from camel.interpreters import SubprocessInterpreter
interpreter = SubprocessInterpreter()
shell_command = "echo 'Hello from SubprocessInterpreter!'"
result_str = interpreter.run(code=shell_command, code_type="bash")
print(f"Result: {result_str.strip()}")
Provides full isolationâcode runs in a Docker container, protecting your host system and supporting any dependencies.Requires Docker installed.
Install Docker
```python from camel.interpreters import DockerInterpreter
interpreter = 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()}")
</Card>
<Card icon="book-open" title="IPython Interpreter (JupyterKernel)" className="my-6">
Interactive, stateful execution in a Jupyter-like Python kernelâmaintains session state and supports rich outputs.
<br/><br/>
```python
from camel.interpreters import JupyterKernelInterpreter
interpreter = 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)
Run code in a secure, scalable, cloud-based environmentâno local setup needed, great for running untrusted or complex code.E2B Documentation
```python from camel.interpreters import E2BInterpreter
interpreter = E2BInterpreter() python_code_in_e2b = "print('Hello from E2BInterpreter!')" result = interpreter.run(code=python_code_in_e2b, code_type="python") print(result)
</Card>
<AccordionGroup>
<Accordion title="Best Practices">
<ul>
<li>Use <b>InternalPythonInterpreter</b> only for trusted and simple Python code.</li>
<li><b>Subprocess</b> and <b>Docker</b> interpreters are better for code isolation and dependency management.</li>
<li>Prefer <b>Docker</b> for any untrusted code or when extra libraries are needed.</li>
<li><b>E2B Interpreter</b> is ideal for scalable, managed, and safe cloud executionâno local risk.</li>
<li>For interactive, multi-step logic, leverage <b>JupyterKernelInterpreter</b> for persistent session state.</li>
<li>Always validate and sanitize user inputs if agents dynamically construct code for execution.</li>
</ul>
</Accordion>
<Accordion title="Troubleshooting & Tips">
<ul>
<li>If Docker isnât working, verify your Docker daemon is running and you have the correct permissions.</li>
<li>For E2B, check API key and account limits if code doesnât execute.</li>
<li>Long-running scripts are best managed in <b>Subprocess</b> or <b>Docker</b> interpreters with timeout controls.</li>
<li>Use session resets (where supported) to avoid cross-task state bleed in Jupyter/IPython interpreters.</li>
</ul>
</Accordion>
</AccordionGroup>