AutoGen Code Execution
Opt in to sandboxed local code execution for framework: autogen with Docker on by default
Enable sandboxed local code execution for framework: autogen runs via a single YAML flag — off by default so LLM-generated code never runs on your host without consent.
Quick Start
- Simple opt-in (Docker on)
Set
code_execution: true— the wrapper defaultswork_dirtocodinganduse_dockertoTrue.yaml framework: autogen topic: Plot a sine wave and save it as sine.png config: autogen: code_execution: truebash export OPENAI_API_KEY=sk-... praisonai agents.yaml --framework autogen - Custom work_dir
Pass a dict to override the sandbox directory —
use_dockerstill defaults toTrue.yaml framework: autogen topic: Analyse sales.csv and print totals config: autogen: code_execution: work_dir: "sandbox" use_docker: true - Local execution (unsafe, dev only)
Setting
use_docker: falseruns generated code directly on the host and logs a warning.yaml framework: autogen config: autogen: code_execution: use_docker: false # LLM code runs on the host — dev only
How It Works
The wrapper resolves code_execution into AutoGen’s code_execution_config before it builds the UserProxyAgent.
The user_proxy is constructed with the resolved code_execution_config and the resolved human_input_mode. When the LLM emits a code block, the user_proxy runs it in the sandbox path; when nothing is opted in, code_execution_config is False and no code runs.
Configuration Options
Every option lives under config.autogen.* in your team YAML.
Option (config.autogen.*) | Type | Default | Description | ||
|---|---|---|---|---|---|
code_execution | bool \ | dict \ | None | None (disabled) | False/None → off; True → {work_dir: "coding", use_docker: True}; dict merged with use_docker: True default. Unrecognised values log a warning and disable execution. |
code_execution.work_dir | str | "coding" | Working directory for generated code | ||
code_execution.use_docker | bool | True (when opted-in) | Sandbox in Docker. Setting False logs a warning and runs on the host. | ||
human_input_mode | str | "TERMINATE" | Passed to UserProxyAgent. Overrideable per YAML. Previously forced to "NEVER". |
Precedence Ladder
code_execution accepts a bool for the common case and a dict for overrides.
# Level 1: Bool (simplest — off by default)
framework: autogen
config:
autogen:
code_execution: true # Docker on, work_dir=coding
# Level 2: Dict (custom overrides)
framework: autogen
config:
autogen:
code_execution:
work_dir: "sandbox"
use_docker: true
# Level 3: Override human_input_mode
framework: autogen
config:
autogen:
code_execution: true
human_input_mode: "ALWAYS" # or NEVER, TERMINATE (default)Failure Scenario
When use_docker: false the wrapper emits this warning before running code on the host:
framework=autogen: code_execution is enabled with use_docker=False;
LLM-generated code will run directly on the host.
Set config.autogen.code_execution.use_docker: true to sandbox.Best Practices
Keep Docker on for anything shared
use_docker: true (the opt-in default) sandboxes generated code. Only drop to use_docker: false on a throwaway local machine, never in CI or on a server.
Opt in explicitly after upgrading
Runs that previously relied on the old implicit host execution now do nothing until you add config.autogen.code_execution: true. Add it deliberately so the security posture is visible in the YAML.
Use a dedicated work_dir
Point work_dir at a disposable folder (e.g. sandbox) so generated files stay isolated and easy to clean up between runs.
Choose human_input_mode for your loop
TERMINATE (the new default) lets an operator step in at the end of a turn. Use NEVER for fully automated runs or ALWAYS for interactive review.