diff --git a/docs/source/en/tutorials/secure_code_execution.md b/docs/source/en/tutorials/secure_code_execution.md index 60887f6..daa8ee9 100644 --- a/docs/source/en/tutorials/secure_code_execution.md +++ b/docs/source/en/tutorials/secure_code_execution.md @@ -60,7 +60,7 @@ For maximum security, you can use our integration with E2B to run code in a sand For this, you will need to setup your E2B account and set your `E2B_API_KEY` in your environment variables. Head to [E2B's quickstart documentation](https://e2b.dev/docs/quickstart) for more information. -Then you can install it with `pip install e2b-code-interpreter python-dotenv`. +Then you can install it with `pip install "smolagents[e2b]"`. Now you're set! diff --git a/pyproject.toml b/pyproject.toml index d510ece..0e6645b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,8 +20,6 @@ dependencies = [ "pillow>=11.0.0", "markdownify>=0.14.1", "duckduckgo-search>=6.3.7", - "python-dotenv>=1.0.1", - "e2b-code-interpreter>=1.0.3", "torchvision" ] @@ -38,6 +36,10 @@ transformers = [ "transformers>=4.0.0", "smolagents[torch]", ] +e2b = [ + "e2b-code-interpreter>=1.0.3", + "python-dotenv>=1.0.1", +] gradio = [ "gradio>=5.8.0", ] @@ -55,10 +57,11 @@ quality = [ "ruff>=0.9.0", ] all = [ - "smolagents[accelerate,audio,gradio,litellm,mcp,openai,transformers]", + "smolagents[accelerate,audio,e2b,gradio,litellm,mcp,openai,transformers]", ] test = [ "pytest>=8.1.0", + "python-dotenv>=1.0.1", # For test_all_docs "smolagents[all]", ] dev = [ diff --git a/src/smolagents/e2b_executor.py b/src/smolagents/e2b_executor.py index 393e572..488f3f7 100644 --- a/src/smolagents/e2b_executor.py +++ b/src/smolagents/e2b_executor.py @@ -20,8 +20,6 @@ import textwrap from io import BytesIO from typing import Any, List, Tuple -from dotenv import load_dotenv -from e2b_code_interpreter import Sandbox from PIL import Image from .tool_validation import validate_tool_attributes @@ -29,11 +27,23 @@ from .tools import Tool from .utils import BASE_BUILTIN_MODULES, instance_to_source -load_dotenv() +try: + from dotenv import load_dotenv + + load_dotenv() +except ModuleNotFoundError: + pass class E2BExecutor: def __init__(self, additional_imports: List[str], tools: List[Tool], logger): + try: + from e2b_code_interpreter import Sandbox + except ModuleNotFoundError: + raise ModuleNotFoundError( + """Please install 'e2b' extra to use E2BExecutor: `pip install "smolagents[e2b]"`""" + ) + self.custom_tools = {} self.sbx = Sandbox() # "qywp2ctmu2q7jzprcf4j") # TODO: validate installing agents package or not