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
SandboxState snapshot from a CapabilitySet.
CapabilitySet
required
The capability set to serialize.
SandboxState
A new
SandboxState instance containing the serialized capabilities.fromJson
SandboxState from a JSON string.
string
required
The JSON string to parse.
SandboxState
A new
SandboxState instance.Methods
toJson
string
JSON representation of the sandbox state.
toCaps
CapabilitySet from this state.
CapabilitySet
A new
CapabilitySet with the same capabilities as the original.Properties
netBlocked
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.