From 5257453c4cabdff7fcff03da5bd0c64040095b62 Mon Sep 17 00:00:00 2001 From: chengyongru <2755839590@qq.com> Date: Tue, 31 Mar 2026 23:47:23 +0800 Subject: [PATCH] feat(exec): add command_wrapper for sandbox support Allow users to wrap shell commands in a sandbox (e.g. bubblewrap, firejail, nsjail) via config, without nanobot baking in any sandbox backend. The template supports {command} and {cwd} placeholders with plain string replacement. --- README.md | 2 + docs/COMMAND_WRAPPER.md | 86 +++++++++++++++++++++++++++++ nanobot/agent/loop.py | 1 + nanobot/agent/subagent.py | 1 + nanobot/agent/tools/shell.py | 9 ++- nanobot/config/schema.py | 1 + tests/tools/test_tool_validation.py | 50 +++++++++++++++++ 7 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 docs/COMMAND_WRAPPER.md diff --git a/README.md b/README.md index 8a8c864d0..98d3a7810 100644 --- a/README.md +++ b/README.md @@ -1387,6 +1387,8 @@ MCP tools are automatically discovered and registered on startup. The LLM can us | `tools.restrictToWorkspace` | `false` | When `true`, restricts **all** agent tools (shell, file read/write/edit, list) to the workspace directory. Prevents path traversal and out-of-scope access. | | `tools.exec.enable` | `true` | When `false`, the shell `exec` tool is not registered at all. Use this to completely disable shell command execution. | | `tools.exec.pathAppend` | `""` | Extra directories to append to `PATH` when running shell commands (e.g. `/usr/sbin` for `ufw`). | +| `tools.exec.commandWrapper` | `""` | Sandbox wrapper command template. See [Exec Tool Sandbox](docs/COMMAND_WRAPPER.md) for details and examples. | + | `channels.*.allowFrom` | `[]` (deny all) | Whitelist of user IDs. Empty denies all; use `["*"]` to allow everyone. | diff --git a/docs/COMMAND_WRAPPER.md b/docs/COMMAND_WRAPPER.md new file mode 100644 index 000000000..da63a9f08 --- /dev/null +++ b/docs/COMMAND_WRAPPER.md @@ -0,0 +1,86 @@ +# Exec Tool Sandbox (`commandWrapper`) + +The `tools.exec.commandWrapper` config option wraps every shell command in a user-defined template before execution. This allows you to add a sandbox layer (e.g. bubblewrap, firejail, nsjail) without any code changes to nanobot. + +## Configuration + +```json +{ + "tools": { + "exec": { + "commandWrapper": "