smolagents
Published
At a glance
- What it is
- smolagents is an open-source Python library from Hugging Face for building agents in a few lines of code.
- Price from
- Open source Details
- Best for
- Python developers who want a small agent library they can read end to end; Experiments with code-writing agents and open models
- Official site
- huggingface.co
- Last checked
- November 2026
- Watch out for
- By default CodeAgent runs model-generated code in your own environment, which the docs describe as inherently risky.
smolagents is an open-source Python library from Hugging Face for building agents in a few lines of code. It is released under the Apache 2.0 license on GitHub, with documentation on huggingface.co. The project's selling point is size: the README says the core agent logic in agents.py is under 1,000 lines, and the maintainers encourage reading and modifying the source.
The main class is CodeAgent, which writes its actions as Python code snippets rather than JSON tool calls. Tool calls become function calls inside that code, so one step can loop over inputs or combine several tools. A more conventional ToolCallingAgent is also included for JSON-style tool calls. Agents can be arranged in multi-agent hierarchies, pushed to and pulled from the Hugging Face Hub, and run from the command line with the smolagent and webagent commands. webagent drives a browser through helium.
The library is model-agnostic. The README shows Hugging Face inference providers, LiteLLM, OpenAI-compatible servers, local transformers models, llama.cpp, Azure OpenAI and Amazon Bedrock. Tools can come from MCP servers, LangChain or Hub Spaces. The big caveat is security. By default a CodeAgent runs model-generated code in your own environment, and the docs say the built-in LocalPythonExecutor is not a security boundary. For untrusted work they point to E2B, Blaxel, Modal or Docker sandboxes.
Key features
- Code agents
- CodeAgent expresses each action as a Python snippet, with tools called as ordinary functions.
- Small codebase
- The core agent logic is kept under about 1,000 lines so it stays readable and easy to change.
- ToolCallingAgent
- A JSON-style tool-calling agent is available when code actions are not wanted.
- Any model
- Built-in model classes cover HF inference providers, LiteLLM, OpenAI-compatible APIs, transformers, llama.cpp, Azure and Bedrock.
- Tool sources
- Tools can be loaded from MCP servers, LangChain, Hub Spaces or written as Python functions.
- Hub sharing
- Agents and tools can be pushed to and loaded from the Hugging Face Hub.
- Sandboxed execution
- Code can run in E2B, Blaxel, Modal or Docker instead of the local interpreter.
- CLI and multimodal input
- The smolagent and webagent commands run agents from a terminal, and agents accept text, image, video and audio inputs.
Pricing
As of November 2026, smolagents is free, open-source software under the Apache 2.0 license, installed with pip install "smolagents[toolkit]". There is no paid tier for the library. You pay for whatever model provider you connect, such as Hugging Face inference providers, OpenAI or Anthropic through LiteLLM, and for any managed sandbox you choose, such as E2B, Blaxel or Modal, under those vendors' own pricing.
Best for
- Python developers who want a small agent library they can read end to end
- Experiments with code-writing agents and open models
- Projects already using the Hugging Face Hub and inference providers
- Prototyping research or web-browsing agents
Limitations
- By default CodeAgent runs model-generated code in your own environment, which the docs describe as inherently risky.
- The built-in LocalPythonExecutor is documented as best-effort only and not a security sandbox, so production use needs E2B, Blaxel, Modal or Docker.
- Remote sandboxes such as E2B or Modal are separate services with their own accounts and billing.
- It is a Python library, so it fits Python codebases.
- The minimal design means features such as deployment tooling are left to you, unlike frameworks with built-in deploy commands.
Verdict
smolagents suits developers who want a compact, hackable library and like the idea of agents that act by writing code. That same design brings real security work, since safe use depends on a proper sandbox. For larger teams that need graph workflows or hosted deployment, a heavier framework may fit better.
Sources
Written from the vendor's own site and documentation, checked November 2026. We have no paid relationship that affects what this page says.
- github.com /huggingface/smolagents
- huggingface.co /docs/smolagents/index
- huggingface.co /docs/smolagents/tutorials/secure_code_execution
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.