Skip to content

Your lightweight open-source personal agent.

fix: detect tilde paths in restrictToWorkspace shell guard

Nikolas de Hor808064e26bf0
diff --git a/nanobot/agent/tools/shell.py b/nanobot/agent/tools/shell.py
index ce1992092..b4a4044aa 100644
--- a/nanobot/agent/tools/shell.py
+++ b/nanobot/agent/tools/shell.py
@@ -143,10 +143,10 @@ class ExecTool(Tool):
for raw in self._extract_absolute_paths(cmd):
try:
- p = Path(raw.strip()).resolve()
+ p = Path(raw.strip()).expanduser().resolve()
except Exception:
continue
- if p.is_absolute() and cwd_path not in p.parents and p != cwd_path:
+ if not p.is_relative_to(cwd_path):
return "Error: Command blocked by safety guard (path outside working dir)"
return None
@@ -155,4 +155,5 @@ class ExecTool(Tool):
def _extract_absolute_paths(command: str) -> list[str]:
win_paths = re.findall(r"[A-Za-z]:\\[^\s\"'|><;]+", command) # Windows: C:\...
posix_paths = re.findall(r"(?:^|[\s|>])(/[^\s\"'>]+)", command) # POSIX: /absolute only
- return win_paths + posix_paths
+ tilde_paths = re.findall(r"(?:^|[\s|>])(~[^\s\"'>]*)", command) # Tilde: ~/...
+ return win_paths + posix_paths + tilde_paths