Skip to main content
SandboxState provides JSON serialization for capability sets. Use it to persist sandbox configurations, pass them across process boundaries, or store them in configuration files.

Creating State

from_caps

Create a state snapshot from a capability set.
CapabilitySet
required
The capability set to snapshot.
Returns: A new SandboxState instance.

from_json

Deserialize state from a JSON string.
str
required
JSON string to parse.
Returns: A new SandboxState instance. Raises:
  • ValueError - Invalid JSON format

Methods

to_json

Serialize the state to a JSON string. Returns: JSON string representation.

to_caps

Reconstruct a capability set from this state. Returns: A new CapabilitySet instance. Raises:
  • FileNotFoundError - A path in the state no longer exists
to_caps() validates that all paths still exist. If a path was deleted since the state was created, it raises FileNotFoundError.

Properties

net_blocked

True if network access is blocked in this state.

JSON Format

The serialized JSON has this structure:

Use Cases

Persist Configuration

Save sandbox configuration to a file:

Pass Across Processes

Transfer sandbox configuration via environment variable or IPC:

Configuration Validation

Load and validate a configuration file:

Round-Trip Example

Complete example showing serialization round-trip: