> ## Documentation Index
> Fetch the complete documentation index at: https://nono.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# SandboxState

> Serialize and restore capability sets as JSON

`SandboxState` is a JSON-serializable snapshot of a `CapabilitySet`.

Use it when you need to persist a sandbox policy, transmit it between processes,
or build a capability set from previously stored configuration.

## Create state from capabilities

```go theme={null}
state, err := nono.StateFromCaps(caps)
if err != nil {
	return err
}
defer state.Close()
```

## Serialize to JSON

```go theme={null}
data, err := state.JSON()
if err != nil {
	return err
}
```

The returned value is a JSON string.

## Restore from JSON

```go theme={null}
restored, err := nono.StateFromJSON(data)
if err != nil {
	return err
}
defer restored.Close()

caps, err := restored.Caps()
if err != nil {
	return err
}
defer caps.Close()
```

`SandboxState` is safe for concurrent use. Multiple goroutines may call `JSON`
concurrently; `Close` requires exclusive access.
