Skip to content

Commit

Permalink
Adding Podman remote executor Fixes #816
Browse files Browse the repository at this point in the history
Solving bug in Docker executor that makes test fail Fixes #815
  • Loading branch information
maeste committed Feb 27, 2025
1 parent af03d17 commit ff2bba6
Show file tree
Hide file tree
Showing 5 changed files with 426 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/source/en/guided_tour.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ agent.run("Could you get me the title of the page at url 'https://huggingface.co
The execution will stop at any code trying to perform an illegal operation or if there is a regular Python error with the code generated by the agent.

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.
You can also use [E2B code executor](https://e2b.dev/docs#what-is-e2-b) or Docker or Podman 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. For Podman, pass `executor_type="podman"` during initialization.


> [!TIP]
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ docker = [
"docker>=7.1.0",
"websocket-client",
]

e2b = [
"e2b-code-interpreter>=1.0.3",
"python-dotenv>=1.0.1",
Expand All @@ -56,6 +57,10 @@ mlx-lm = [
openai = [
"openai>=1.58.1"
]
podman = [
"podman>=5.4.0",
"websocket-client",
]
telemetry = [
"arize-phoenix",
"opentelemetry-sdk",
Expand All @@ -68,7 +73,7 @@ transformers = [
"smolagents[torch]",
]
all = [
"smolagents[audio,docker,e2b,gradio,litellm,mcp,openai,telemetry,transformers]",
"smolagents[audio,docker,e2b,gradio,litellm,mcp,openai,podman,telemetry,transformers]",
]
quality = [
"ruff>=0.9.0",
Expand Down
10 changes: 6 additions & 4 deletions src/smolagents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
LogLevel,
Monitor,
)
from .remote_executors import DockerExecutor, E2BExecutor
from .remote_executors import DockerExecutor, E2BExecutor, PodmanExecutor
from .tools import Tool
from .utils import (
AgentError,
Expand Down Expand Up @@ -1129,7 +1129,7 @@ class CodeAgent(MultiStepAgent):
grammar (`dict[str, str]`, *optional*): Grammar used to parse the LLM output.
additional_authorized_imports (`list[str]`, *optional*): Additional authorized imports for the agent.
planning_interval (`int`, *optional*): Interval at which the agent will run a planning step.
executor_type (`str`, default `"local"`): Which executor type to use between `"local"`, `"e2b"`, or `"docker"`.
executor_type (`str`, default `"local"`): Which executor type to use between `"local"`, `"e2b"`, `"docker"`, or `"podman"`.
executor_kwargs (`dict`, *optional*): Additional arguments to pass to initialize the executor.
max_print_outputs_length (`int`, *optional*): Maximum length of the print outputs.
**kwargs: Additional keyword arguments.
Expand Down Expand Up @@ -1174,13 +1174,15 @@ def __init__(

def create_python_executor(self, executor_type: str, kwargs: Dict[str, Any]) -> PythonExecutor:
match executor_type:
case "e2b" | "docker":
case "e2b" | "docker" | "podman":
if self.managed_agents:
raise Exception("Managed agents are not yet supported with remote code execution.")
if executor_type == "e2b":
return E2BExecutor(self.additional_authorized_imports, self.logger, **kwargs)
else:
if executor_type == "docker":
return DockerExecutor(self.additional_authorized_imports, self.logger, **kwargs)
if executor_type == "podman":
return PodmanExecutor(self.additional_authorized_imports, self.logger, **kwargs)
case "local":
return LocalPythonExecutor(
self.additional_authorized_imports,
Expand Down
Loading

0 comments on commit ff2bba6

Please sign in to comment.