sandbox
sandbox
¶
Bubblewrap (bwrap) process sandbox for agent execution isolation.
Wraps subprocess execution in a bubblewrap namespace providing: - PID namespace isolation (--unshare-pid) - Network isolation (--unshare-net) - Filesystem sandboxing via bind mounts - MCP socket forwarding via bind-mounted Unix sockets - Automatic cleanup on conductor death (--die-with-parent)
Resource governance (memory caps, CPU quotas, PID limits) is handled separately via systemd-run or prlimit — NOT baked into bwrap args. bwrap handles namespace isolation; resource limits are orthogonal.
A bwrap subprocess starts in ~4ms. The sandbox overhead is measured in kilobytes, not megabytes.
Classes¶
ResourceLimits
dataclass
¶
Optional resource caps for sandbox processes.
These are NOT enforced by bwrap itself — they are metadata consumed by the conductor's resource governance layer (systemd-run, prlimit). BwrapSandbox stores them for the caller to apply separately.
Attributes¶
memory_limit_mb
class-attribute
instance-attribute
¶
Maximum memory in MB. None means no cap.
cpu_quota_percent
class-attribute
instance-attribute
¶
CPU quota as a percentage (e.g. 50 = 50%%). None means no cap.
pid_limit
class-attribute
instance-attribute
¶
Maximum number of PIDs. None means no cap.
BwrapSandbox
¶
Wraps subprocess execution in a bubblewrap namespace.
Given a workspace path, shared directories, MCP sockets, and optional resource limits, produces the bwrap command line that sets up isolation boundaries. The conductor uses this to wrap agent subprocess execution.
Usage::
sandbox = BwrapSandbox(
workspace=Path("/tmp/agent-ws"),
shared_dirs=[Path("/tmp/shared/specs")],
mcp_sockets=[Path("/tmp/mzt/mcp/github.sock")],
resource_limits=ResourceLimits(memory_limit_mb=512),
)
cmd = sandbox.wrap_command(["python", "agent_script.py"])
# cmd is ["bwrap", "--bind", "/tmp/agent-ws", ...]
Source code in src/marianne/isolation/sandbox.py
Functions¶
wrap_command
¶
Prepend bwrap args to a command.
Produces a complete bwrap invocation that isolates the inner command in a namespace with the configured bind mounts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
The command to execute inside the sandbox. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Full bwrap command line as a list of strings. |
Source code in src/marianne/isolation/sandbox.py
is_available
async
staticmethod
¶
Check if bwrap is installed and runnable.
Returns:
| Type | Description |
|---|---|
bool
|
True if |