smolagents
Hugging Face's barebones library for agents that think in code
The README explicitly documents sandboxed execution of model-generated code via Blaxel, E2B, Modal, or Docker — one of the few projects in this batch with a concrete, checkable security design described up front; no isolated verification was performed for this review.
Core agent logic is kept to roughly 1,000 lines of code by the maintainers' own account, which aids reviewability, but no multi-task retest was performed.
Positioned as a lightweight agent library where agents "think in code" rather than plain text tool calls — better suited to developers with some engineering background than no-code users.
Documentation site (huggingface.co/docs/smolagents) is well structured with clean example code, and Hub integration makes sharing/reusing agents easy.
28.5k+ stars, model-agnostic and modality-agnostic (text/vision/video/audio) with strong ecosystem integration, though actual output quality depends on the task and chosen model.
This review relied on the public README and repo metadata only — no independent install or sandbox-execution reproduction was performed.
- CodeAgent executes model-generated code — for untrusted input or externally exposed use, use one of the documented sandboxes (Blaxel/E2B/Modal/Docker) rather than running unsandboxed locally
- Targets developers with Python engineering background; the onboarding bar is higher for no-code users
- This is a static review; no isolated dynamic verification was performed
What it does & when to use it
smolagents is a lightweight agent library from Hugging Face whose defining feature is having agents express their actions in code rather than plain text (CodeAgent), with the core logic kept to roughly 1,000 lines. It's model-agnostic — usable with local transformers/ollama models or any provider like OpenAI and Anthropic — and modality-agnostic, supporting text, vision, video, and audio input, with model-generated code executable inside sandboxes like Blaxel, E2B, Modal, or Docker for safety.
Lets a developer define an agent in a few lines of Python, give it tools (e.g. web search), and bind a model; the agent plans and executes actions by writing code rather than emitting text that's parsed into tool calls afterward, paired with sandboxed execution to reduce the risk of running arbitrary code directly. It can also pull in ready-made tools from MCP servers, LangChain, or a Hugging Face Space.
- Need a lightweight, small-codebase agent framework that's easy to audit rather than a heavyweight platform
- Want to reuse existing tools from the Hugging Face Hub, or share an agent you've built
- Agent scenarios involving multi-modal input — vision, video, or audio
- Cases with real code-execution safety requirements that need sandboxed isolation for model-generated code
Pros & cons
- Small core codebase (~1,000 lines), easy to audit and understand rather than being a black-box platform
- Officially documents concrete sandbox options (Blaxel/E2B/Modal/Docker) — unusually transparent security design for a project in this category
- Model-agnostic and modality-agnostic, and can directly reuse tools from MCP servers, LangChain, and Hugging Face Spaces
- Backed by Hugging Face with tight Hub integration, making agents easy to share and reuse
- Targets developers with a Python engineering background — no graphical interface for no-code users
- CodeAgent fundamentally executes model-generated code; running it locally without one of the documented sandboxes carries risk
- This review did not verify actual runtime behavior under any specific sandbox configuration
How to install
pip install "smolagents[toolkit]" installs the default toolset; a leaner install without extra tools is also available — see the official docs for details.
How to use
Runs in a few lines of code:
from smolagents import CodeAgent, WebSearchTool, InferenceClientModel
model = InferenceClientModel()
agent = CodeAgent(tools=[WebSearchTool()], model=model, stream_outputs=True)
agent.run("your task description")You can also share a built agent to the Hugging Face Hub with agent.push_to_hub(...).
Compared to similar agents
Unlike multi-agent orchestration frameworks such as CrewAI or LangGraph that focus on process orchestration, smolagents concentrates on how a single agent executes actions — expressing tool calls as code rather than text/JSON, closer to a lightweight library than a heavyweight platform. If you need to orchestrate multiple collaborating agents, CrewAI or LangGraph fits better; if you need a simple, auditable, model-agnostic single-agent base, smolagents is more direct.