Files
agent-zero/plugins/_code_execution/helpers/destinations.py
T
Jan Tomášek 540ec7d854 Replace gVisor with PRoot and shared copy-on-write sandbox files
Run guests under separate Linux UIDs while retaining PRoot fake-root for
installers. Share immutable image files through hardlinks and copy each file
before mutation. Preserve existing disk roots during migration, maintain worker
bindings and lifecycle behavior, and remove gVisor sidecars and the Compose
seccomp override.

Build the pinned runtime in a disposable stage, bootstrap source updates, and
keep Unix socket scratch paths short. Preserve worker request ACLs and translate
fake-root Unix credentials for browser audio.

Validation: 3,398 unit tests and six real runtime checks passed. Verified default
Docker seccomp, missing-bundle image build, source bootstrap, persistent PTY,
worker RPC, browser render/input/audio/downloads/profile restart, and WebUI HTTP
startup. Fresh base is about 71 MiB smaller; a clean default sandbox uses about
9.7 MiB private disk. Ubuntu AppArmor and ARM64 were not available to test.
2026-11-16 18:42:18 +00:00

72 lines
2.4 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Literal
from helpers.extension import call_extensions_async
DestinationKind = Literal["local", "sandbox", "host"]
@dataclass(frozen=True, slots=True)
class ExecutionDestination:
id: str
kind: DestinationKind
label: str
description: str
target: str = ""
status: str = "available"
async def get_code_execution_destinations(agent: Any) -> list[ExecutionDestination]:
destinations = [
ExecutionDestination(
id="local",
kind="local",
label="Agent Zero system",
description="The operating system running Agent Zero; use only for Agent Zero itself or its core files.",
)
]
await call_extensions_async(
"code_execution_destinations",
agent=agent,
destinations=destinations,
)
unique: dict[str, ExecutionDestination] = {}
for destination in destinations:
if destination.id and destination.id not in unique:
unique[destination.id] = destination
return list(unique.values())
async def resolve_code_execution_destination(
agent: Any, requested: str
) -> ExecutionDestination:
requested = str(requested or "default").strip() or "default"
destinations = await get_code_execution_destinations(agent)
for destination in destinations:
if destination.id == requested:
return destination
if requested in {"local", "host", "default"}:
raise ValueError(f"Code execution destination is not currently available: {requested}")
# Named sandboxes are intentionally lazy: a missing one is created when its
# first shell connects. The sandbox plugin still validates the exact name.
try:
from plugins._sandboxing.helpers.manager import validate_name
sandbox_name = requested.split(":", 1)[1] if requested.startswith("sandbox:") else requested
validate_name(sandbox_name)
except (ImportError, IndexError, ValueError, RuntimeError) as exc:
raise ValueError(f"Unknown code execution destination: {requested}") from exc
return ExecutionDestination(
id=requested,
kind="sandbox",
target=sandbox_name,
label=f"Sandbox {sandbox_name}",
description="A PRoot sandbox that will be created or woken on first use.",
status="missing",
)