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: README.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ limitations under the License.
34
34
35
35
✨ **Simplicity**: the logic for agents fits in ~1,000 lines of code (see [agents.py](https://github.com/huggingface/smolagents/blob/main/src/smolagents/agents.py)). We kept abstractions to their minimal shape above raw code!
36
36
37
-
🧑💻 **First-class support for Code Agents**. Our [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent) writes its actions in code (as opposed to "agents being used to write code"). To make it secure, we support executing in sandboxed environments via [E2B](https://e2b.dev/), [Modal](https://modal.com/), Docker, or Pyodide+Deno WebAssembly sandbox.
37
+
🧑💻 **First-class support for Code Agents**. Our [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent) writes its actions in code (as opposed to "agents being used to write code"). To make it secure, we support executing in sandboxed environments via [Blaxel](https://blaxel.ai), [E2B](https://e2b.dev/), [Modal](https://modal.com/), Docker, or Pyodide+Deno WebAssembly sandbox.
38
38
39
39
🤗 **Hub integrations**: you can [share/pull tools or agents to/from the Hub](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_hub) for instant sharing of the most efficient agents!
40
40
@@ -239,7 +239,7 @@ Writing actions as code snippets is demonstrated to work better than the current
239
239
240
240
Especially, since code execution can be a security concern (arbitrary code execution!), we provide options at runtime:
241
241
- a secure python interpreter to run code more safely in your environment (more secure than raw code execution but still risky)
242
-
- a sandboxed environment using [E2B](https://e2b.dev/) or Docker (removes the risk to your own system).
242
+
- a sandboxed environment using [Blaxel](https://blaxel.ai), [E2B](https://e2b.dev/), or Docker (removes the risk to your own system).
243
243
244
244
Alongside [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent), we also provide the standard [`ToolCallingAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.ToolCallingAgent) which writes actions as JSON/text blobs. You can pick whichever style best suits your use case.
245
245
@@ -265,7 +265,7 @@ This comparison shows that open-source models can now take on the best closed mo
265
265
## Security
266
266
267
267
Security is a critical consideration when working with code-executing agents. Our library provides:
268
-
- Sandboxed execution options using [E2B](https://e2b.dev/), [Modal](https://modal.com/), Docker, or Pyodide+Deno WebAssembly sandbox
268
+
- Sandboxed execution options using [Blaxel](https://blaxel.ai), [E2B](https://e2b.dev/), [Modal](https://modal.com/), Docker, or Pyodide+Deno WebAssembly sandbox
269
269
- Best practices for running agent code securely
270
270
271
271
For security policies, vulnerability reporting, and more information on secure agent execution, please see our [Security Policy](SECURITY.md).
Copy file name to clipboardExpand all lines: docs/source/en/guided_tour.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,7 +85,7 @@ This could also be authorized by using `numpy.*`, which will allow `numpy` as we
85
85
86
86
The execution will stop at any code trying to perform an illegal operation orif there is a regular Python error with the code generated by the agent.
87
87
88
-
You can also use [E2B code executor](https://e2b.dev/docs#what-is-e2-b) or Docker instead of a local Python interpreter. For E2B, first [set the `E2B_API_KEY` environment variable](https://e2b.dev/dashboard?tab=keys) and then pass `executor_type="e2b"` upon agent initialization. For Docker, pass `executor_type="docker"` during initialization.
88
+
You can also use [Blaxel](https://blaxel.ai), [E2B](https://e2b.dev/docs#what-is-e2-b), or Docker instead of a local Python interpreter. For Blaxel, first [set the `BL_API_KEY` and `BL_WORKSPACE` environment variables](https://app.blaxel.ai/profile/security) and then pass `executor_type="blaxel"` upon agent initialization. For E2B, first [set the `E2B_API_KEY` environment variable](https://e2b.dev/dashboard?tab=keys) and then pass `executor_type="e2b"`. For Docker, pass `executor_type="docker"`.
Copy file name to clipboardExpand all lines: docs/source/en/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Key features of `smolagents` include:
12
12
13
13
✨ **Simplicity**: The logic for agents fits in ~thousand lines of code. We kept abstractions to their minimal shape above raw code!
14
14
15
-
🧑💻 **First-class support for Code Agents**: [`CodeAgent`](reference/agents#smolagents.CodeAgent) writes its actions in code (as opposed to "agents being used to write code") to invoke tools or perform computations, enabling natural composability (function nesting, loops, conditionals). To make it secure, we support [executing in sandboxed environment](tutorials/secure_code_execution) via [E2B](https://e2b.dev/) or via Docker.
15
+
🧑💻 **First-class support for Code Agents**: [`CodeAgent`](reference/agents#smolagents.CodeAgent) writes its actions in code (as opposed to "agents being used to write code") to invoke tools or perform computations, enabling natural composability (function nesting, loops, conditionals). To make it secure, we support [executing in sandboxed environment](tutorials/secure_code_execution) via [Blaxel](https://blaxel.ai), [E2B](https://e2b.dev/), or Docker.
16
16
17
17
📡 **Common Tool-Calling Agent Support**: In addition to CodeAgents, [`ToolCallingAgent`](reference/agents#smolagents.ToolCallingAgent) supports usual JSON/text-based tool-calling for scenarios where that paradigm is preferred.
1.**Running individual code snippets in a sandbox**: This approach (left side of diagram) only executes the agent-generated Python code snippets in a sandbox while keeping the rest of the agentic system in your local environment. It's simpler to set up using `executor_type="e2b"`, `executor_type="modal"`, or
121
+
1.**Running individual code snippets in a sandbox**: This approach (left side of diagram) only executes the agent-generated Python code snippets in a sandbox while keeping the rest of the agentic system in your local environment. It's simpler to set up using `executor_type="blaxel"`, `executor_type="e2b"`, `executor_type="modal"`, or
122
122
`executor_type="docker"`, but it doesn't support multi-agents and still requires passing state data between your environment and the sandbox.
123
123
124
124
2.**Running the entire agentic system in a sandbox**: This approach (right side of diagram) runs the entire agentic system, including the agent, model, and tools, within a sandbox environment. This provides better isolation but requires more manual setup and may require passing sensitive credentials (like API keys) to the sandbox environment.
125
125
126
126
This guide describes how to set up and use both types of sandbox approaches for your agent applications.
127
127
128
+
### Blaxel setup
129
+
130
+
#### Installation
131
+
132
+
1. Create a Blaxel account at [blaxel.ai](https://blaxel.ai)
133
+
2. Install the required packages:
134
+
```bash
135
+
pip install 'smolagents[blaxel]'
136
+
```
137
+
138
+
#### Running your agent with Blaxel: quick start
139
+
140
+
We provide a simple way to use a Blaxel Sandbox: simply add `executor_type="blaxel"` to the agent initialization, as follows:
141
+
142
+
```py
143
+
from smolagents import InferenceClientModel, CodeAgent
144
+
145
+
with CodeAgent(model=InferenceClientModel(), tools=[], executor_type="blaxel") as agent:
146
+
agent.run("Can you give me the 100th Fibonacci number?")
147
+
```
148
+
149
+
> [!TIP]
150
+
> Using the agent as a context manager (with the `with` statement) ensures that the Blaxel sandbox is cleaned up immediately after the agent completes its task.
151
+
> Alternatively, you can manually call the agent's `cleanup()` method.
152
+
153
+
This solution sends the agent state to the server at the start of each `agent.run()`.
154
+
Then the models are called from the local environment, but the generated code will be sent to the sandbox for execution, and only the output will be returned.
155
+
156
+
Blaxel provides fast-launching virtual machines that start from hibernation in under 25ms and scale back to zero after inactivity while maintaining memory state, making it an excellent choice for agent applications that require quick, secure code execution.
157
+
158
+
> [!TIP]
159
+
> For even stronger security isolation, you can host your entire agent remotely on Blaxel. This provides complete sandboxing of the agent, model, and tools. See the [Blaxel agent hosting documentation](https://docs.blaxel.ai/Agents/Develop-an-agent-py) for details.
160
+
128
161
### E2B setup
129
162
130
163
#### Installation
@@ -423,7 +456,7 @@ agent.run("Can you give me the 100th Fibonacci number?")
423
456
424
457
### Best practices for sandboxes
425
458
426
-
These key practices apply to both E2B and Docker sandboxes:
459
+
These key practices apply to Blaxel, E2B, and Docker sandboxes:
427
460
428
461
- Resource management
429
462
- Set memory and CPU limits
@@ -449,9 +482,10 @@ As illustrated in the diagram earlier, both sandboxing approaches have different
449
482
450
483
### Approach 1: Running just the code snippets in a sandbox
451
484
-**Pros**:
452
-
- Easier to set up with a simple parameter (`executor_type="e2b"` or `executor_type="docker"`)
485
+
- Easier to set up with a simple parameter (`executor_type="blaxel"`, `executor_type="e2b"`, or `executor_type="docker"`)
453
486
- No need to transfer API keys to the sandbox
454
487
- Better protection for your local environment
488
+
- Fast execution with Blaxel's hibernation technology (<25ms startup)
455
489
-**Cons**:
456
490
- Doesn't support multi-agents (managed agents)
457
491
- Still requires transferring state between your environment and the sandbox
0 commit comments