agent: v3.0 — fix cfg scope bug in execute_command (update + shell commands)

self_update(cfg) and shell allow_shell_commands check both referenced cfg
from run() scope, but execute_command() is a standalone function. Fixed by
calling load_config() locally in each branch that needs it.
This commit is contained in:
2026-06-11 21:10:08 +00:00
parent 2767a858dd
commit 8b7f597e76
3 changed files with 214 additions and 6 deletions
+4 -2
View File
@@ -525,12 +525,14 @@ def execute_command(cmd: dict) -> dict:
return {"success": r.returncode == 0, "output": r.stdout}
elif cmd_type == "update":
updated = self_update(cfg)
_cfg = load_config()
updated = self_update(_cfg)
return {"success": True, "updated": updated}
elif cmd_type == "shell":
# Guard reads LOCAL config, not the server-supplied payload
if not cfg.get("allow_shell_commands", False):
_cfg = load_config()
if not _cfg.get("allow_shell_commands", False):
return {"success": False, "error": "Shell commands not enabled in agent config"}
cmd_str = cmd_data.get("command", "")
r = subprocess.run(cmd_str, shell=True, capture_output=True, text=True, timeout=30)