Smolagents code agents

From mouadja02/skills · View interactive version

Smolagents code agents is an AI agent skill from the GitHub repository mouadja02/skills. Use when building Hugging Face smolagents, code-executing agents, Python-action agents, Hub-shared tools, or lightweight agent prototypes that need sandboxing and provider flexibility.

How to use this skill

Skill file

Smolagents Code Agents

Use code actions when an agent benefits from loops, variables, data transforms, and multi-call tool composition. Treat generated code as untrusted unless it runs in a real sandbox.

Use When

Build Pattern

  1. Choose CodeAgent when actions need Python control flow; choose ToolCallingAgent for simple structured tool calls.
  2. Keep tools small, typed, and side-effect explicit.
  3. Configure the model through environment variables or a provider object, never hard-code secrets.
  4. Run code execution in Docker, E2B, Modal, Blaxel, or another isolation boundary.
  5. Allow imports by explicit whitelist only.
  6. Stream logs and capture intermediate observations for debugging.
  7. Add a task-level timeout and max-step budget.

Safety Baseline

Never treat LocalPythonExecutor as a security boundary for untrusted code. Use it only for trusted local experiments.

Generate a starter safety scaffold:

python scripts/smolagent_safety_scaffold.py --name research_agent

Review sandboxing-checklist.md before running any agent that executes model-written code.

Quick Selection

| Requirement | Choose |

| --- | --- |

| Agent writes Python actions | CodeAgent |

| Strict JSON-like tool calls | ToolCallingAgent |

| Untrusted tasks or web data | Sandboxed executor |

| Local model experiments | TransformersModel or Ollama-compatible provider |

| Hosted provider flexibility | InferenceClientModel, LiteLLMModel, or OpenAI-compatible model |

Common Mistakes

| Mistake | Fix |

| --- | --- |

| Running untrusted code locally | Use Docker or managed sandbox |

| Exposing broad filesystem access | Mount a temporary workspace only |

| Giving tools vague docstrings | Make inputs, outputs, and side effects explicit |

| Letting agents import anything | Whitelist imports per task |

| Shipping without trace logs | Persist steps, code snippets, tool outputs, and final answer |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.