Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/google/adk/agents/config_agent_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,20 @@ def _resolve_agent_class(agent_class: str) -> type[BaseAgent]:
" BaseAgent."
)


_BLOCKED_YAML_KEYS = frozenset({"args"})
_ENFORCE_DENYLIST = False
_BLOCKED_MODULES = frozenset({
"os", "sys", "subprocess", "builtins",
"importlib", "shutil", "socket",
"ctypes", "pickle", "marshal",
})
_BLOCKED_YAML_KEYS = frozenset({
"args",
"model_code",
"tools",
"callbacks",
"input_schema",
"output_schema",
})
_ENFORCE_DENYLIST = True


def _set_enforce_denylist(value: bool) -> None:
Expand Down Expand Up @@ -214,7 +225,11 @@ def resolve_code_reference(code_config: CodeConfig) -> Any:
"""
if not code_config or not code_config.name:
raise ValueError("Invalid CodeConfig.")

top_level = code_config.name.split(".")[0]
if top_level in _BLOCKED_MODULES:
raise ValueError(
f"Module '{top_level}' is not allowed in code references."
)
module_path, obj_name = code_config.name.rsplit(".", 1)
module = importlib.import_module(module_path)
obj = getattr(module, obj_name)
Expand Down
Loading