Skip to main content
CapabilitySet is the core class for defining what a sandboxed process can access. It collects filesystem capabilities, network settings, and command filters before applying the sandbox.

Constructor

Creates a new empty capability set with no permissions granted.

Methods

allow_path

Grant access to a directory and all its contents recursively.
str
required
Path to the directory. Must exist and be a directory.
AccessMode
required
Access level to grant: READ, WRITE, or READ_WRITE.
Raises:
  • FileNotFoundError - Path does not exist
  • ValueError - Path is not a directory
The path is canonicalized (symlinks resolved) when added. On macOS, /tmp becomes /private/tmp.

allow_file

Grant access to a single file only (not its parent directory).
str
required
Path to the file. Must exist and be a regular file.
AccessMode
required
Access level to grant: READ, WRITE, or READ_WRITE.
Raises:
  • FileNotFoundError - Path does not exist
  • ValueError - Path is not a file

block_network

Block all network access for the sandboxed process.
Network is allowed by default. Call block_network() to restrict it.

proxy_only

Restrict network access to proxy-only mode. Blocks all outbound network except localhost TCP to the proxy’s listening port. Use with start_proxy() to allow filtered network access through the proxy while blocking all direct connections.
ProxyHandle
required
A running proxy handle from start_proxy().
proxy_only() and block_network() are mutually exclusive — calling one overrides the other. Use proxy_only() when you want filtered network access; use block_network() when you want no network at all.

platform_rule

Add a platform-specific sandbox rule. On macOS, this is a Seatbelt S-expression. Ignored on Linux.
str
required
Platform-specific rule string.
Raises:
  • ValueError - Rule is malformed or grants dangerous access (e.g., root access)
Platform rules are validated for safety. Rules that grant excessive permissions (like root filesystem access) are rejected.

deduplicate

Remove duplicate filesystem capabilities, keeping the highest access level. User-granted capabilities take priority over system-granted ones.

path_covered

Check if a path is covered by an existing directory capability.
str
required
Path to check.
Returns: True if the path would be accessible via an existing capability.
This checks against resolved/canonicalized paths. Use the resolved path from a capability for accurate results.

fs_capabilities

Get all filesystem capabilities in the set. Returns: List of FsCapability objects.

summary

Get a human-readable summary of all capabilities. Returns: Multi-line string describing the capability set.
Output:

Properties

is_network_blocked

True if network access is blocked.