From 8626caff742c6e68f6fc4a951bc2ec8d9ab2424b Mon Sep 17 00:00:00 2001 From: Re-bin Date: Tue, 10 Feb 2026 07:39:15 +0000 Subject: [PATCH] fix: prevent safety guard from blocking relative paths in exec tool --- nanobot/agent/tools/shell.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nanobot/agent/tools/shell.py b/nanobot/agent/tools/shell.py index 143d187..18eff64 100644 --- a/nanobot/agent/tools/shell.py +++ b/nanobot/agent/tools/shell.py @@ -128,14 +128,17 @@ class ExecTool(Tool): cwd_path = Path(cwd).resolve() win_paths = re.findall(r"[A-Za-z]:\\[^\\\"']+", cmd) - posix_paths = re.findall(r"/[^\s\"']+", cmd) + # Only match absolute paths — avoid false positives on relative + # paths like ".venv/bin/python" where "/bin/python" would be + # incorrectly extracted by the old pattern. + posix_paths = re.findall(r"(?:^|[\s|>])(/[^\s\"'>]+)", cmd) for raw in win_paths + posix_paths: try: - p = Path(raw).resolve() + p = Path(raw.strip()).resolve() except Exception: continue - if cwd_path not in p.parents and p != cwd_path: + if p.is_absolute() and cwd_path not in p.parents and p != cwd_path: return "Error: Command blocked by safety guard (path outside working dir)" return None