create_sandbox#

Run commands and agent-written programs inside an operating-system boundary. See the guide.

zett_agent.sandbox.factory.create_sandbox(policy=None, *, backend=SandboxBackend.AUTO, require_isolation=False, memory_strategy=MemoryStrategy.AUTO)[source]#

Create the sandbox for this machine, failing loudly rather than weakening it.

A backend that exists but cannot run (bubblewrap missing, namespaces forbidden) raises SandboxUnavailableError: the command is never run unsandboxed because of a problem the caller can fix. The one case that degrades is a platform with no backend at all, where AUTO returns a PassthroughSandbox and emits a SandboxWarning. Pass require_isolation=True to make that case an error too.

Parameters:
  • policy (SandboxPolicy | None) – The boundary to enforce. Defaults to a read-only policy.

  • backend (SandboxBackend | str) – A backend to force, or AUTO for this platform’s own.

  • require_isolation (bool) – Raise instead of returning a sandbox that isolates nothing.

  • memory_strategy (MemoryStrategy | str) – How to enforce memory_bytes; see MemoryStrategy.

Raises:
Return type:

Sandbox

Examples

Take whatever this platform offers:

sandbox = create_sandbox(SandboxPolicy.workspace_write("/work/project"))

Refuse to run anywhere that cannot isolate:

sandbox = create_sandbox(policy, require_isolation=True)