feat(exec): allow extra bwrap bind roots

This commit is contained in:
yu-xin-c
2026-07-27 00:31:00 +08:00
committed by Xubin Ren
parent 5d8046deef
commit 01a11b3980
7 changed files with 263 additions and 6 deletions
+30
View File
@@ -8,6 +8,7 @@ platform-specific binaries (all subprocess calls are mocked).
import asyncio
import shutil
import sys
from pathlib import Path
from unittest.mock import AsyncMock, patch
import pytest
@@ -473,6 +474,35 @@ class TestSandboxPlatform:
spawned_cmd = mock_spawn.call_args[0][0]
assert "bwrap" in spawned_cmd
@pytest.mark.asyncio
async def test_bwrap_receives_configured_bind_roots(self):
"""Configured bwrap bind roots should be forwarded to the sandbox wrapper."""
mock_proc = AsyncMock()
mock_proc.communicate.return_value = (b"sandboxed", b"")
mock_proc.returncode = 0
with (
patch("nanobot.agent.tools.shell._IS_WINDOWS", False),
patch("nanobot.agent.tools.shell.wrap_command", return_value="bwrap -- sh -c ls") as mock_wrap,
patch.object(ExecTool, "_spawn", return_value=mock_proc),
patch.object(ExecTool, "_guard_command", return_value=None),
):
tool = ExecTool(
sandbox="bwrap",
working_dir="/workspace",
sandbox_ro_binds=["/home/user/.local/bin"],
sandbox_rw_binds=["/home/user/.cache/uv"],
)
await tool.execute(command="ls")
kwargs = mock_wrap.call_args.kwargs
assert kwargs["sandbox_ro_binds"] == [
str(Path("/home/user/.local/bin").resolve(strict=False))
]
assert kwargs["sandbox_rw_binds"] == [
str(Path("/home/user/.cache/uv").resolve(strict=False))
]
# ---------------------------------------------------------------------------
# end-to-end (mocked subprocess, full execute path)