Skip to content

API Reference parrot_formdesigner.services.sandbox.gvisor_pool

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.sandbox.gvisor_pool

View source

gVisor-isolated worker pool for tiers 3-4 (FEAT-459 / M10, OQ-4).

Hard prerequisite: is_available() gates whether tier-3/4 bundles may ever load (TASK-3164's git loader, TASK-3172's tier router both call it). When runsc is absent, callers refuse to load tier-3/4 bundles at BOOT — this module performs NO silent downgrade to a weaker isolation mechanism (not Docker, not bare subprocess). Structurally mirrors services/sandbox/pool.py's SubprocessWorkerPool (recycling, health checks, bounded acquire queue) but backs each worker with a gVisor (runsc) container via SandboxConfig instead of a bare asyncio.subprocess.

Class GVisorSandbox

A sandbox backed by a gVisor-isolated worker.

Parameter Type Default Description
worker GVisorWorker
pool GVisorWorkerPool
config SandboxConfig

Method GVisorSandbox.reset

Reset the sandbox to a known state.

reset(seed_state: dict[str, Any] | None) -> None

Parameter Type Default Description
seed_state dict[str, Any] | None Initial state to load. None empties the store.

Method GVisorSandbox.health_check

Check whether the sandbox is operational.

health_check() -> bool

Returns: bool — True if the sandbox is healthy.

Method GVisorSandbox.snapshot

Capture a deterministic snapshot of the current world state.

snapshot() -> dict[str, Any]

Returns: dict[str, Any] — A deep copy of the current state.

Method GVisorSandbox.exec

Execute a shell command inside the sandbox.

exec(cmd: list[str]) -> ExecResult

Parameter Type Default Description
cmd list[str] Command and arguments to execute.

Returns: ExecResult — ExecResult with exit code, stdout, stderr.

Class GVisorUnavailableError

Raised by init if instantiated while is_available() is False.

Class GVisorWorker

A single gVisor-isolated worker instance.

Parameter Type Default Description
worker_id str
sandbox_tool SandboxTool
invocations int 0
last_health_check float 0.0
is_healthy bool True

Fields:

Field Type Default Description
worker_id str
sandbox_tool SandboxTool
invocations int 0
last_health_check float 0.0
is_healthy bool True

Class GVisorWorkerPool

Warm gVisor-isolated worker pool for CapabilityTier BROKERED/TOOLKIT.

Parameter Type Default Description
config SandboxConfig | None None gVisor SandboxConfig. Defaults to SandboxConfig(runtime="runsc", network="none") — network stays "none"; tier 3/4 outbound access is host-broker-mediated only (TASK-3171), never the worker's own network stack.
tier34_pool_size int 2 Warm workers held per process (default 2 — spec §7 OQ-6: tier 3/4 traffic is rare by design; containers are expensive to hold warm).
recycle_after_invocations int 500 Recycle worker after this many uses.
recycle_after_seconds int 3600 Recycle worker after this many seconds.
acquire_queue_timeout_ms int 2000 Timeout for waiting on the acquire queue.
max_queue_depth int 32 Maximum number of waiting acquire requests.
health_check_interval_s int 30 Interval between health checks.
cold_start_timeout_ms int 5000 Timeout for cold start of a new worker.

Method GVisorWorkerPool.is_available

True when the runsc runtime is present and usable on PATH.

A pure presence probe (shutil.which) — does NOT attempt to spawn a container, matching the cheap, boot-time-safe check TASK-3164's loader and TASK-3172's router both need before deciding whether to load/route any tier-3/4 bundle at all.

is_available() -> bool

Returns: bool

Method GVisorWorkerPool.acquire

Acquire a gVisor-isolated worker.

See SubprocessWorkerPool.acquire (TASK-3169) for the bounded-queue / cold-start-timeout shape this mirrors — the only difference is the underlying spawn mechanism (a gVisor container via self._config, not a bare subprocess).

acquire(spec: SandboxSpec) -> Sandbox

Parameter Type Default Description
spec SandboxSpec Sandbox configuration specification.

Returns: Sandbox — A gVisor-isolated Sandbox instance.

Raises:

  • PoolExhaustedError — when the acquire queue is full and timeout expires.

Method GVisorWorkerPool.release

Return a sandbox to the pool (or recycle it).

release(sandbox: Sandbox) -> None

Parameter Type Default Description
sandbox Sandbox The sandbox to release.

Class PoolExhaustedError

Raised when the acquire queue is full and timeout expires.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally