← All notes

Run smolagents CodeAgent tools in a secure sandbox

Answer: smolagents CodeAgent writes tool calls as Python code, which can run locally or in a sandbox. Local execution is convenient but is not robust isolation. The secure-execution guide says the robust options are remote sandboxes such as E2B or Docker.

CodeAgent versus ToolCallingAgent

smolagents comes with two agent classes: CodeAgent and ToolCallingAgent. The key difference is how actions are specified and executed: code generation versus structured tool calling. CodeAgent generates tool calls as Python code snippets. Execution can be local (potentially unsecure) or a secure sandbox. Tools are exposed as Python functions via bindings. Strengths include expressiveness and flexibility; limitations include the risk of errors and the need for a secure execution environment. ToolCallingAgent writes tool calls as structured JSON, a common format used in many frameworks such as the OpenAI API, without code execution. Tools are defined with a JSON schema: name, description, and parameter types.

Sandbox approaches

No sandbox can ever be completely secure. Running generated code in your local environment always carries some inherent risk. Robust security isolation for generated code comes from remote execution options like E2B or Docker. A malicious attack is less likely with well-known models from trusted inference providers, but the risk is not zero. Prefer a remote execution sandbox for high-security work or less trusted models.

| CodeAgent | Docker | |---|---| | CodeAgent | Python code snippets, local or sandboxed | | ToolCallingAgent | structured JSON tool calls, no code execution | | E2B or Docker | remote execution sandboxes |

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Hugging Face smolagents, Guided tour; huggingface/smolagents (GitHub), Secure code execution. Apache-2.0; Apache-2.0. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Hugging Face smolagents, Guided tour; huggingface/smolagents (GitHub), Secure code execution. Apache-2.0; Apache-2.0.

Cite this

Permanent ID: iil:note:9qwpmzk5

iinventedlight. 2026. "Run smolagents CodeAgent tools in a secure sandbox." iinventedlight Library, iil:note:9qwpmzk5, version of 2026-11-19. https://iinventedlight.com/library/notes/smolagents-code-execution/. License: CC-BY-4.0.

@misc{iil_note_9qwpmzk5,
  author = {{iinventedlight}},
  title = {{Run smolagents CodeAgent tools in a secure sandbox}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/smolagents-code-execution/},
  note = {Permanent ID iil:note:9qwpmzk5. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/smolagents-code-execution.md.