python/packages/autogen-core/src/autogen_core/tools/_function_tool.py
The FunctionTool._from_config() method executes arbitrary Python code via exec() when loading a configuration from an untrusted source. While there is a security warning, the design fundamentally allows code execution.
# Line 159-171 in _function_tool.py
exec(import_code, exec_globals) # Executes arbitrary import statements
exec(config.source_code, exec_globals) # Executes arbitrary function code- Attacker creates a malicious
FunctionToolConfigwithsource_codecontaining arbitrary Python - Config is loaded via
ComponentLoader.load_component()orFunctionTool._from_config() - Arbitrary code executes in the process context
- Severity: CRITICAL
- Impact: Complete system compromise, data exfiltration, lateral movement
- Likelihood: MEDIUM (requires loading config from untrusted source)
- Security warning in documentation
- Trusted namespace validation in
ComponentLoader.load_component() - No default mechanism to load untrusted configs
- Add runtime validation that source_code doesn't contain dangerous patterns
- Consider sandboxed execution (e.g., RestrictedPython) for untrusted configs
- Require explicit opt-in flag for loading FunctionTools from external configs
- Add audit logging for FunctionTool config loading