Skip to main content
The SandboxState class enables serializing a capability set to JSON and restoring it later. This is primarily useful for passing sandbox configuration to child processes.

Use Cases

  • Child Process Inheritance: Serialize the sandbox state, pass it to a child process via environment variable, and have the child apply the same restrictions
  • Configuration Storage: Save sandbox configurations to disk for later use
  • Debugging: Inspect the serialized state to understand what capabilities are configured

Static Methods

fromCaps

Create a SandboxState snapshot from a CapabilitySet.
CapabilitySet
required
The capability set to serialize.
SandboxState
A new SandboxState instance containing the serialized capabilities.

fromJson

Deserialize a SandboxState from a JSON string.
string
required
The JSON string to parse.
SandboxState
A new SandboxState instance.
Throws an error if the JSON is invalid or malformed.

Methods

toJson

Serialize the state to a JSON string.
string
JSON representation of the sandbox state.

toCaps

Reconstruct a CapabilitySet from this state.
CapabilitySet
A new CapabilitySet with the same capabilities as the original.
Throws an error if any paths in the state no longer exist on the filesystem.

Properties

netBlocked

Returns true if network access is blocked in this state.

Example: Child Process Inheritance

Parent Process

Child Process (worker.js)

Example: Configuration File

Save Configuration

Load Configuration

JSON Schema

The serialized JSON has the following structure:
The JSON structure is considered internal and may change between versions. Always use fromJson() and toJson() rather than parsing manually.