The CodeInterpreterTool
is a powerful tool designed for executing Python 3 code within a secure, isolated environment.
CodeInterpreterTool
The CodeInterpreterTool
enables CrewAI agents to execute Python 3 code that they generate autonomously. This functionality is particularly valuable as it allows agents to create code, execute it, obtain the results, and utilize that information to inform subsequent decisions and actions.
There are several ways to use this tool:
This is the primary option. The code runs in a secure, isolated Docker container, ensuring safety regardless of its content. Make sure Docker is installed and running on your system. If you don’t have it, you can install it from here.
If Docker is unavailable — either not installed or not accessible for any reason — the code will be executed in a restricted Python environment - called sandbox. This environment is very limited, with strict restrictions on many modules and built-in functions.
NOT RECOMMENDED FOR PRODUCTION
This mode allows execution of any Python code, including dangerous calls to sys, os..
and similar modules. Check out how to enable this mode
The CodeInterpreterTool
logs the selected execution strategy to STDOUT
To use this tool, you need to install the CrewAI tools package:
The following example demonstrates how to use the CodeInterpreterTool
with a CrewAI agent:
You can also enable code execution directly when creating an agent:
unsafe_mode
The CodeInterpreterTool
accepts the following parameters during initialization:
False
. Use with caution!code-interpreter:latest
When using the tool with an agent, the agent will need to provide:
[]
Here’s a more detailed example of how to integrate the CodeInterpreterTool
with a CrewAI agent:
The CodeInterpreterTool
uses Docker to create a secure environment for code execution:
The tool performs the following steps:
By default, the CodeInterpreterTool
runs code in an isolated Docker container, which provides a layer of security. However, there are still some security considerations to keep in mind:
unsafe_mode
parameter allows code to be executed directly on the host machine, which should only be used in trusted environments.The CodeInterpreterTool
provides a powerful way for CrewAI agents to execute Python code in a relatively secure environment. By enabling agents to write and run code, it significantly expands their problem-solving capabilities, especially for tasks involving data analysis, calculations, or other computational work. This tool is particularly useful for agents that need to perform complex operations that are more efficiently expressed in code than in natural language.
The CodeInterpreterTool
is a powerful tool designed for executing Python 3 code within a secure, isolated environment.
CodeInterpreterTool
The CodeInterpreterTool
enables CrewAI agents to execute Python 3 code that they generate autonomously. This functionality is particularly valuable as it allows agents to create code, execute it, obtain the results, and utilize that information to inform subsequent decisions and actions.
There are several ways to use this tool:
This is the primary option. The code runs in a secure, isolated Docker container, ensuring safety regardless of its content. Make sure Docker is installed and running on your system. If you don’t have it, you can install it from here.
If Docker is unavailable — either not installed or not accessible for any reason — the code will be executed in a restricted Python environment - called sandbox. This environment is very limited, with strict restrictions on many modules and built-in functions.
NOT RECOMMENDED FOR PRODUCTION
This mode allows execution of any Python code, including dangerous calls to sys, os..
and similar modules. Check out how to enable this mode
The CodeInterpreterTool
logs the selected execution strategy to STDOUT
To use this tool, you need to install the CrewAI tools package:
The following example demonstrates how to use the CodeInterpreterTool
with a CrewAI agent:
You can also enable code execution directly when creating an agent:
unsafe_mode
The CodeInterpreterTool
accepts the following parameters during initialization:
False
. Use with caution!code-interpreter:latest
When using the tool with an agent, the agent will need to provide:
[]
Here’s a more detailed example of how to integrate the CodeInterpreterTool
with a CrewAI agent:
The CodeInterpreterTool
uses Docker to create a secure environment for code execution:
The tool performs the following steps:
By default, the CodeInterpreterTool
runs code in an isolated Docker container, which provides a layer of security. However, there are still some security considerations to keep in mind:
unsafe_mode
parameter allows code to be executed directly on the host machine, which should only be used in trusted environments.The CodeInterpreterTool
provides a powerful way for CrewAI agents to execute Python code in a relatively secure environment. By enabling agents to write and run code, it significantly expands their problem-solving capabilities, especially for tasks involving data analysis, calculations, or other computational work. This tool is particularly useful for agents that need to perform complex operations that are more efficiently expressed in code than in natural language.