fix(exec): preserve bwrap workspace masking

This commit is contained in:
Xubin Ren
2026-07-27 00:31:00 +08:00
parent 22e61003f9
commit cf6ca13b6d
5 changed files with 80 additions and 9 deletions
+24
View File
@@ -387,6 +387,30 @@ def test_exec_bind_roots_do_not_widen_guard_without_bwrap(tmp_path):
assert "path outside working dir" in blocked
def test_exec_bwrap_bind_parent_does_not_widen_workspace_guard(tmp_path, monkeypatch):
workspace = tmp_path / "workspace"
workspace.mkdir()
secret = tmp_path / "config.json"
secret.write_text("secret")
monkeypatch.setattr("nanobot.agent.tools.shell._IS_WINDOWS", False)
tool = ExecTool(
working_dir=str(workspace),
restrict_to_workspace=True,
sandbox="bwrap",
sandbox_ro_binds=[str(tmp_path)],
)
blocked = tool._guard_command(
f"cat {secret}",
str(workspace),
restrict_to_workspace=True,
workspace_root=str(workspace),
)
assert blocked is not None
assert "path outside working dir" in blocked
# --- format command blocking -----------------------------------------------
+21
View File
@@ -201,6 +201,27 @@ class TestBwrapBackend:
assert "relative/bin" not in tokens
assert "relative/cache" not in tokens
def test_custom_workspace_parent_binds_are_ignored(self, tmp_path):
ws = tmp_path / "private" / "project"
parent = ws.parent.resolve(strict=False)
result = wrap_command(
"bwrap",
"cat ../config.json",
str(ws),
str(ws),
sandbox_ro_binds=[str(parent)],
sandbox_rw_binds=[str(parent)],
)
tokens = _parse(result)
ro_try_indices = [i for i, token in enumerate(tokens) if token == "--ro-bind-try"]
ro_try_pairs = {(tokens[i + 1], tokens[i + 2]) for i in ro_try_indices}
bind_try_indices = [i for i, token in enumerate(tokens) if token == "--bind-try"]
bind_try_pairs = {(tokens[i + 1], tokens[i + 2]) for i in bind_try_indices}
assert (str(parent), str(parent)) not in ro_try_pairs
assert (str(parent), str(parent)) not in bind_try_pairs
class TestUnknownBackend:
def test_raises_value_error(self, tmp_path):