smolagents
Hugging Face's barebones library for agents that think in code.
Best for
Teams building workflows and agents, especially if you want to keep your key on your own device and mix cloud and local models.
Skip it if
You need features specific to another tool; check the alternatives below.
Rank in Automation & Agents
13th of 39 by editor score
Key Safety
93/100 (grade A), safer than 55% of its category
Overview
smolagents lets you build agents that write and run Python code to call tools, in a few lines. It works with Hugging Face inference, OpenAI, Anthropic and any LiteLLM-supported model on your own keys, or local models via Transformers and Ollama, with sandboxed execution options.
Key features
- Code agents
- Any LiteLLM model
- Sandboxed execution
- Hub tool sharing
Works with these providers
10 provider options, more than the 7.8 average for automation & agents. Usage is billed by the provider at its list price.
Our verdict
smolagents is ranked 13th of 39 automation & agents on BYOK Tools and sits mid-pack on key safety. Its standout strength: minimal and readable. The main trade-off: A library, not an app.
What we like
- Minimal and readable
- Backed by Hugging Face
Watch out for
- A library, not an app
How smolagents compares
Against the highest-rated automation & agents on BYOK Tools. Scores are out of 5 (editor) and 100 (Key Safety).
| Tool | Editor score | Key Safety | Pricing | Providers | Open source | Local models | Key stays local |
|---|---|---|---|---|---|---|---|
| smolagents | 4.3 | 93 | Open source | 10 | |||
| n8n | 4.7 | 78 | Freemium | 14 | – | ||
| Dify | 4.6 | 78 | Open source | 14 | – | ||
| Home Assistant | 4.6 | 78 | Open source | 5 | – | ||
| Windmill | 4.5 | 78 | Freemium | 11 | – |
- Prioritising key safety? Mastra scores 100/100.
How to use smolagents with your own API key
- 1
Create an API key
Get a key from your provider's console: OpenAI, Anthropic, Google Gemini, Groq, Mistral, Together AI. Create a separate key just for smolagents so you can revoke it on its own.
- 2
Set a spending limit
Set a monthly budget or usage cap in the provider dashboard before you start. It is the simplest protection against a leaked key or a runaway agent.
- 3
Install smolagents
Install smolagents from the command line using the instructions in its repository or docs.
- 4
Add your key
Paste the key into smolagents's provider or model settings. Your key is stored on your device and requests go directly to the provider.
- 5
What it costs to run smolagents
Pricing for smolagents itself: Open source (Free & open source). Model usage is billed by your provider. Estimated monthly API spend by usage level, using live list prices:
| Model | Light~5 messages a day | Regular~20 messages a day | Heavy~80 messages a day |
|---|---|---|---|
| GPT-5.4 NanoOpenAI · Budget | $0.072 | $0.53 | $5.98 |
| GPT-6.2 Astra ProOpenAI · Flagship | $2.48 | $19 | $222 |
| Claude Haiku 5.5Anthropic · Budget | $0.031 | $0.24 | $2.78 |
| Claude Fable 5.2Anthropic · Flagship | $2.48 | $19 | $222 |
| Gemini 4 NeonGoogle Gemini · Budget | $0.93 | $7.13 | $83 |
| Gemma 4 26B A4B Google Gemini · Flagship | $0.016 | $0.13 | $1.69 |
Estimates assume typical chat-length messages with conversation history and no prompt caching. Prices from OpenRouter's public models API. Run your own numbers or use a local model for $0.
BYOK Key Safety Score
Key handling in smolagents
Grade A
Your key is stored on your device and requests go directly to the provider.
Category average: 88/100
- Key storage40/40
Key stays on your device; requests go direct to the provider.
- Auditable code25/25
Open source: anyone can verify how keys are handled.
- Self-hosting8/15
Runs as a local app, but not as a self-hosted service.
- Offline option10/10
Supports local models, so no key is needed at all for private work.
- Provider choice10/10
10 provider options, which lets you pick the provider whose data terms you trust.
Whatever the score, give each app its own key, set a monthly spend limit with your provider, and revoke keys you no longer use. Read the key-safety checklist.
smolagents FAQ
- Does smolagents support bring your own key?
- Yes. smolagents accepts your own API key from OpenAI, Anthropic, Google Gemini, Groq, Mistral, Ollama, Azure OpenAI, AWS Bedrock, Together AI and OpenAI-compatible. Usage is billed by the provider at its API rates.
- Where does smolagents store my API key?
- On your device. Requests go directly from smolagents to the provider. Its BYOK Tools Key Safety Score is 93/100.
- Is smolagents free?
- Open source: Free & open source. API usage is billed separately by your model provider.
- How much does it cost to use smolagents with my own API key?
- For regular use (about 20 messages a day), API costs run from roughly $0.13 to $19 a month depending on the model, based on current list prices. Local models cost nothing per token.
- Is smolagents open source?
- Yes. The source code is at https://github.com/huggingface/smolagents.
- Can smolagents run local models?
- Yes. It can connect to local runtimes such as Ollama or LM Studio, so no API key is needed for private or offline use.
- Which platforms does smolagents support?
- CLI, macOS, Linux, Windows.
- What are the best alternatives to smolagents?
- Popular alternatives include MetaGPT, Stagehand, Cua and Agent S. See the comparison table above for pricing, providers and key safety side by side.
Community reviews
No reviews yet.
Alternatives to smolagents
All automation & agents →MetaGPT
Automation & Agents
Multi-agent framework that simulates a software company from one prompt.
Stagehand
Automation & Agents
SDK for AI browser automation that mixes code with natural-language actions.
Cua
Automation & Agents
Open-source infrastructure for computer-use agents, with sandboxes and SDKs.
Agent S
Automation & Agents
State-of-the-art open-source computer-use agent framework.
OpenClaw
Automation & Agents
Self-hosted personal AI assistant that lives in your messaging apps.
OpenManus
Automation & Agents
Open-source general AI agent framework inspired by Manus.