Skip to content

Your lightweight open-source personal agent.

feat(exec): add path_append config to extend PATH for subprocess

aiguozhi123456abcce1e1db32
diff --git a/nanobot/agent/tools/shell.py b/nanobot/agent/tools/shell.py
index e3592a7d5..c11fa2d92 100644
--- a/nanobot/agent/tools/shell.py
+++ b/nanobot/agent/tools/shell.py
@@ -19,6 +19,7 @@ class ExecTool(Tool):
deny_patterns: list[str] | None = None,
allow_patterns: list[str] | None = None,
restrict_to_workspace: bool = False,
+ path_append: str = "/usr/sbin:/usr/local/sbin",
):
self.timeout = timeout
self.working_dir = working_dir
@@ -35,6 +36,7 @@ class ExecTool(Tool):
]
self.allow_patterns = allow_patterns or []
self.restrict_to_workspace = restrict_to_workspace
+ self.path_append = path_append
@property
def name(self) -> str:
@@ -67,12 +69,17 @@ class ExecTool(Tool):
if guard_error:
return guard_error
+ env = os.environ.copy()
+ if self.path_append:
+ env["PATH"] = env.get("PATH", "") + ":" + self.path_append
+
try:
process = await asyncio.create_subprocess_shell(
command,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=cwd,
+ env=env,
)
try:
diff --git a/nanobot/config/schema.py b/nanobot/config/schema.py
index fe8dd83d9..dd856fea7 100644
--- a/nanobot/config/schema.py
+++ b/nanobot/config/schema.py
@@ -252,6 +252,7 @@ class ExecToolConfig(Base):
"""Shell exec tool configuration."""
timeout: int = 60
+ path_append: str = "/usr/sbin:/usr/local/sbin"
class MCPServerConfig(Base):