@@ -80,6 +80,31 @@ def _resolve_agent_class(agent_class: str) -> type[BaseAgent]:
8080 )
8181
8282
83+ _BLOCKED_YAML_KEYS = frozenset ({"args" })
84+ _ENFORCE_DENYLIST = False
85+
86+
87+ def _set_enforce_denylist (value : bool ) -> None :
88+ global _ENFORCE_DENYLIST
89+ _ENFORCE_DENYLIST = value
90+
91+
92+ def _check_config_for_blocked_keys (node : Any , filename : str ) -> None :
93+ """Recursively check if the configuration contains any blocked keys."""
94+ if isinstance (node , dict ):
95+ for key , value in node .items ():
96+ if key in _BLOCKED_YAML_KEYS :
97+ raise ValueError (
98+ f"Blocked key { key !r} found in { filename !r} . "
99+ f"The '{ key } ' field is not allowed in agent configurations "
100+ "because it can execute arbitrary code."
101+ )
102+ _check_config_for_blocked_keys (value , filename )
103+ elif isinstance (node , list ):
104+ for item in node :
105+ _check_config_for_blocked_keys (item , filename )
106+
107+
83108def _load_config_from_path (config_path : str ) -> AgentConfig :
84109 """Load an agent's configuration from a YAML file.
85110
@@ -100,6 +125,9 @@ def _load_config_from_path(config_path: str) -> AgentConfig:
100125 with open (config_path , "r" , encoding = "utf-8" ) as f :
101126 config_data = yaml .safe_load (f )
102127
128+ if _ENFORCE_DENYLIST :
129+ _check_config_for_blocked_keys (config_data , config_path )
130+
103131 return AgentConfig .model_validate (config_data )
104132
105133
0 commit comments