smolagents
Hugging Face's minimalist library for building agents that write and execute Python code as their primary action.
smolagents
smolagents is a barebones library from Hugging Face for building agents that think in code. The entire agent logic fits in ~1000 lines of code. CodeAgent writes actions as executable Python — enabling natural composability through loops, conditionals, and function calls — while ToolCallingAgent supports standard JSON tool-calling.
Key Features
- Code-first agents: Actions are Python snippets executed in a sandboxed interpreter, not JSON blobs
- Secure sandboxing: Execute code safely via Modal, E2B, Docker, or Blaxel
- Any model: Works with Hugging Face models, OpenAI, Anthropic, local Ollama, and any LiteLLM-compatible provider
- Hub integration: Share and load agents and tools directly as Hugging Face Spaces
- Multi-agent: Compose agents hierarchically with a manager orchestrating specialists
- Minimal surface area: Easy to audit, extend, and debug
Quick Start
pip install smolagents
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
agent = CodeAgent(
tools=[DuckDuckGoSearchTool()],
model=HfApiModel("meta-llama/Llama-3.3-70B-Instruct")
)
agent.run("What were the biggest AI breakthroughs of 2025?")
Add to ai-supply
npx ai-supply add smolagents-code-agents
Curated mirror of the open-source smolagents (Apache-2.0). Get it from the source.
Compromise signals — malicious or tampered code (leaked secrets, backdoors, a dropped executable) — reduce the score, and known dependency CVEs carry a bounded penalty (they warrant review but never QUARANTINE — update the dependency to clear). Other dangerous-by-capability traits are risk surface, expected for some capabilities. Every finding is mapped to its OWASP control below.
Findings mapped to the OWASP Top 10 for LLM Applications (2025) and the OWASP Machine Learning Security Top 10. Expand any flagged control for the exact findings — compromise reduces the score; expected/risk-surface do not, except a known CVE, which carries a small bounded penalty (high/critical → Review).
The same gate an agent runs before installing (POST /api/v1/trust/smolagents-code-agents/check). Click a policy:
Consume smolagents programmatically. Authenticate with an API key or session — see Authorize an agent.
# Agents: CHECK BEFORE YOU INSTALL (no auth) — score, grade, level, capability manifest
curl https://ai-supply.store/api/v1/trust/smolagents-code-agents
# Gate against your org policy (returns { pass, violations })
curl -X POST https://ai-supply.store/api/v1/trust/smolagents-code-agents/check \
-H "Content-Type: application/json" \
-d '{"minGrade":"B","denyPermissions":["shell"],"denyUnknownEgress":true}'
# CLI
npx ai-supply add smolagents-code-agents
# REST (install → download)
curl -X POST https://ai-supply.store/api/v1/listings/smolagents-code-agents/install \
-H "Authorization: Bearer $AIM_KEY"
# MCP tool
install_listing({ "slug": "smolagents-code-agents" })OpenAPI spec →Curated mirror — latest upstream source. See the repository for tagged releases.