Hugging Face's entry, and a genuinely different paradigm from the other three. Instead of the model requesting a JSON tool call one at a time, smolagents' default CodeAgent has the model write actual Python code that runs in a constrained interpreter.
Core concepts
CodeAgentvsToolCallingAgent:CodeAgentwrites and executes real Python per turn;ToolCallingAgentis the drop-in JSON-tool-calling alternative if you want parity with other frameworks. smolagents Docs- Why code execution is faster for multi-step tasks: A model can loop, branch, and combine several tool calls in one generated code block instead of one round trip per tool call.
- The
@tooldecorator andArgs:docstrings: smolagents parses theArgs:section of a docstring directly to build the tool schema — a malformed block breaks tool discovery, not just the docs. - Security is not automatic: The default local executor is explicitly documented as not a sandbox — escaping it is expected behavior. Use
executor_type="e2b"or"docker"for anything beyond local experimentation. additional_authorized_imports: Any import a tool needs beyond the safe allowlist must be explicitly declared when constructing the agent.
Why it matters
It's the quickest way to try code-as-action with Hugging Face models, and it forces the sandbox question on day one instead of after launch.
Where people get stuck
- Running CodeAgent without a real sandbox. That is arbitrary code execution on your machine.
- Assuming a small library means no ops work. You still need logging, limits and model routing.
- Using CodeAgent when your tools are few and stable. ToolCallingAgent is simpler to audit.
Try this
Run a ToolCallingAgent with one calculator tool locally. Then read the CodeAgent docs and list the sandbox you'd need before trying it.
Interview question
CodeAgent vs ToolCallingAgent?
CodeAgent writes Python for multi-step logic and needs strong isolation. ToolCallingAgent uses structured tool calls and is easier to audit when the tools are fixed.
Resources
YouTube learning
Core concepts from video walkthroughs:

