brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
execution-and-safetyConfigure smolagents CodeAgent execution safely: local imports, executor_type choices, remote sandboxes, PythonInterpreterTool, and sandbox troubleshooting.
Independent GitHub snapshot · Automated classification · Original documentation governs
Use this sub-skill when a task involves how CodeAgent executes Python, how to limit or authorize imports, how to choose executor_type, or how to troubleshoot local and remote execution failures.
Route elsewhere when the request is mainly about:
model-providers.cli-and-ui.agent-workflows.Tool subclasses, MCP, or tool serialization: use tools-and-integrations.Prefer this decision order:
CodeAgent(..., executor_type="local") only for trusted tasks and low-risk code, because LocalPythonExecutor is a restricted AST interpreter but not a complete security sandbox.additional_authorized_imports narrowly, one package or submodule at a time; avoid "*" unless the user explicitly accepts local execution risk.executor_type="docker", "e2b", "modal", or "blaxel" for untrusted prompts, web-browsing contexts, public-facing agents, or higher-risk code.agent.cleanup() for remote executors so sandboxes/containers terminate promptly.from smolagents import CodeAgent
agent = CodeAgent(
tools=[],
model=model,
executor_type="local",
additional_authorized_imports=["math", "statistics"],
max_print_outputs_length=10_000,
executor_kwargs={"timeout_seconds": 10},
)
Key points:
additional_authorized_imports extends smolagents' built-in safe module list for local code execution."numpy" allows import numpy; use "numpy.random" for that submodule or "numpy.*" for the package tree.LocalPythonExecutor checks that authorized modules are importable during initialization, except wildcard "*".max_print_outputs_length truncates captured stdout, not the returned Python value.executor_kwargs={"timeout_seconds": N} sets the local execution timeout; None disables it and should be avoided for untrusted code.For exact constructor behavior, see executor-reference.md. For risk patterns and sandbox selection, see security-workflows.md. For errors, see troubleshooting.md.
CodeAgent accepts exactly these executor names:
executor_type | Best fit | Extra |
|---|---|---|
"local" | Trusted local workflows, fastest setup | base package |
"docker" | Self-hosted isolation, local container control | smolagents[docker] |
"e2b" | Managed cloud sandbox with E2B account/API setup | smolagents[e2b] |
"modal" | Managed Modal sandbox with Modal account/API setup | smolagents[modal] |
"blaxel" | Managed Blaxel sandbox, fast hibernating VMs | smolagents[blaxel] |
Remote executor pattern:
from smolagents import CodeAgent
with CodeAgent(
tools=[],
model=model,
executor_type="docker",
additional_authorized_imports=["numpy"],
executor_kwargs={"build_new_image": False},
) as agent:
result = agent.run("Compute a small numeric result without writing files.")
Remote execution details:
additional_authorized_imports becomes the list of packages installed in the remote environment.allow_pickle=True enables pickle fallback for complex objects but can execute arbitrary code during deserialization; use it only in fully trusted environments.Use PythonInterpreterTool when a tool-calling agent needs a calculator-like Python tool rather than CodeAgent code actions:
from smolagents import PythonInterpreterTool
python_tool = PythonInterpreterTool(
authorized_imports=["math"],
timeout_seconds=10,
)
The tool returns a string containing captured stdout and the final output. Its authorized_imports follows the same allow-list idea as LocalPythonExecutor and includes base built-in modules automatically.
Use the bundled helper for safe local validation before constructing a real agent:
python sub-skills/execution-and-safety/scripts/check_executor_config.py --executor-type local --imports math statistics --tiny-local-check
python sub-skills/execution-and-safety/scripts/check_executor_config.py --executor-type docker --imports numpy --explain-only
The helper performs parser-only checks by default. It never starts Docker, Modal, E2B, or Blaxel, never reads credentials, and never runs network calls. --tiny-local-check executes only a tiny in-process local interpreter smoke test.