You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tools/codeinterpretertool.mdx
+41-8Lines changed: 41 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,29 @@ icon: code-simple
8
8
9
9
## Description
10
10
11
-
The `CodeInterpreterTool` enables CrewAI agents to execute Python 3 code that they generate autonomously. The code is run in a secure, isolated Docker container, ensuring safety regardless of the content. 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.
11
+
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.
12
12
13
-
## Requirements
13
+
There are several ways to use this tool:
14
+
15
+
### Docker Container (Recommended)
16
+
17
+
This is the primary option. The code runs in a secure, isolated Docker container, ensuring safety regardless of its content.
18
+
Make sure Docker is installed and running on your system. If you don’t have it, you can install it from [here](https://docs.docker.com/get-docker/).
19
+
20
+
### Sandbox environment
21
+
22
+
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.
23
+
This environment is very limited, with strict restrictions on many modules and built-in functions.
24
+
25
+
### Unsafe Execution
26
+
27
+
**NOT RECOMMENDED FOR PRODUCTION**
28
+
This mode allows execution of any Python code, including dangerous calls to `sys, os..` and similar modules. [Check out](/tools/codeinterpretertool#enabling-unsafe-mode) how to enable this mode
29
+
30
+
## Logging
31
+
32
+
The `CodeInterpreterTool` logs the selected execution strategy to STDOUT
14
33
15
-
- Docker must be installed and running on your system. If you don't have it, you can install it from [here](https://docs.docker.com/get-docker/).
The `CodeInterpreterTool` accepts the following parameters during initialization:
80
111
81
112
-**user_dockerfile_path**: Optional. Path to a custom Dockerfile to use for the code interpreter container.
82
113
-**user_docker_base_url**: Optional. URL to the Docker daemon to use for running the container.
83
-
-**unsafe_mode**: Optional. Whether to run code directly on the host machine instead of in a Docker container. Default is `False`. Use with caution!
114
+
-**unsafe_mode**: Optional. Whether to run code directly on the host machine instead of in a Docker container or sandbox. Default is `False`. Use with caution!
115
+
-**default_image_tag**: Optional. Default Docker image tag. Default is `code-interpreter:latest`
84
116
85
117
When using the tool with an agent, the agent will need to provide:
86
118
87
119
-**code**: Required. The Python 3 code to execute.
88
-
-**libraries_used**: Required. A list of libraries used in the code that need to be installed.
120
+
-**libraries_used**: Optional. A list of libraries used in the code that need to be installed. Default is `[]`
89
121
90
122
## Agent Integration Example
91
123
@@ -152,7 +184,7 @@ class CodeInterpreterTool(BaseTool):
@@ -168,8 +200,9 @@ The tool performs the following steps:
168
200
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:
169
201
170
202
1. The Docker container has access to the current working directory, so sensitive files could potentially be accessed.
171
-
2. The `unsafe_mode` parameter allows code to be executed directly on the host machine, which should only be used in trusted environments.
172
-
3. Be cautious when allowing agents to install arbitrary libraries, as they could potentially include malicious code.
203
+
2. If the Docker container is unavailable and the code needs to run safely, it will be executed in a sandbox environment. For security reasons, installing arbitrary libraries is not allowed
204
+
3. The `unsafe_mode` parameter allows code to be executed directly on the host machine, which should only be used in trusted environments.
205
+
4. Be cautious when allowing agents to install arbitrary libraries, as they could potentially include malicious code.
0 commit comments