Skip to content

smolagents

Hugging Face's minimal agent library where agents act by writing and running Python code.

smolagents is a small library built on one idea: instead of emitting structured tool calls, an agent writes Python code and runs it. Expressing actions as code lets a single step do more (loops, composition, logic) than a single tool call can.

It is intentionally tiny, integrates with the Hugging Face ecosystem, and runs generated code in a sandbox.

Where it fits

A fit for tasks where actions are naturally computational and a code-writing agent expresses them more cleanly than a chain of tool calls.

Where it does not fit

Running model-written code raises a real security surface: wrong for environments that cannot accept that, even sandboxed.

Alternatives to smolagents

The closest options on the map, and where each fits instead.

Pairs with

Commonly used alongside it.