Skip to main content
The nono_py module provides functions for applying sandboxes, starting the network proxy, and checking platform support. It also provides policy-loading helpers for filesystem and network policy resolution.

apply

Apply the sandbox with the given capabilities. This is irreversible. Once called, the current process and all child processes can only access resources granted by the capabilities. There is no way to expand permissions after this call.
CapabilitySet
required
The capability set defining permitted operations.
Raises:
  • RuntimeError - Platform not supported or sandbox initialization failed

Example

No escape hatch. Once apply() succeeds:
  • Permissions cannot be expanded
  • The sandbox persists until process exit
  • All child processes inherit the same restrictions
  • There is no “undo” or “disable” function

Error Handling


is_supported

Check if sandboxing is supported on this platform. Returns: True if sandboxing is available.

Example

Platform Requirements

Use support_info() for more detailed information about why sandboxing might not be available.

support_info

Get detailed information about sandbox support on this platform. Returns: SupportInfo object with platform details.

Example

Output examples: macOS:
Linux with Landlock:
Linux without Landlock:

Detailed Platform Check


sandboxed_exec

Run a command in a sandboxed child process while the Python caller remains unsandboxed. The child receives only the capabilities in caps.
CapabilitySet
required
Capability set defining the child’s permitted filesystem and network access.
list[str]
required
Program and arguments to execute, for example ["python", "agent.py"].
str | None
Working directory for the child process.
float | None
Maximum runtime in seconds. On timeout, sandboxed_exec() kills the sandboxed command’s process group and returns exit code 124.
list[tuple[str, str]] | None
Explicit child environment variables. The parent environment is not inherited unless inherit_env=True.
bool
If true, inherit the parent environment and apply env as overrides. Dynamic-loader environment variables such as LD_* and DYLD_* are rejected.
int | None
Optional RLIMIT_NPROC value for the child. This is a per-real-UID kernel limit, not a per-sandbox process-tree limit.
Returns: ExecResult with stdout, stderr, and exit_code. Raises:
  • RuntimeError - Fork failed, sandbox setup failed, or command could not be executed
  • ValueError - Command is empty, timeout is negative, or max_processes is zero

Example

Optional Process Limit

max_processes sets RLIMIT_NPROC before exec. Use it only when sandboxed executions run under a dedicated Unix UID. The kernel counts every process already owned by that UID, so on a normal shared user account a small value can make the sandboxed program’s first fork() fail with EAGAIN instead of providing a per-sandbox process budget.
Use cgroup pids.max, containers, or microVMs for reliable per-execution fork limits.

start_proxy

Start the nono network filtering proxy. Creates a localhost proxy server that provides domain filtering, credential injection, and audit logging for sandboxed child processes. The proxy runs on a background thread and is shut down via the returned handle.
ProxyConfig
required
Proxy configuration including allowed hosts, credential routes, and bind settings.
Returns: ProxyHandle with env_vars(), credential_env_vars(), drain_audit_events(), and shutdown(). Raises:
  • RuntimeError - Proxy failed to start (port in use, etc.)

Example


embedded_policy_json

Return the bundled policy JSON document as a raw string. Returns: JSON text for the embedded policy.

Example


load_policy

Parse a policy JSON document into a Policy object. Returns: Policy with group inspection and resolution helpers. Raises:
  • ValueError - Invalid policy JSON, including unknown policy fields

Example

Policy.resolve_proxy_config() follows the same network field naming used by the main nono profile format:
  • Canonical key: network.allow_domain
  • Accepted aliases: network.allow_proxy, network.proxy_allow
If multiple groups specify different upstream_proxy / external_proxy values, resolution fails with ValueError instead of silently overwriting the earlier proxy. Policy JSON is parsed strictly. Unknown fields are rejected instead of being ignored. When resolving groups with proxy-filtered network policy, resolve_groups() fails closed by blocking direct network access. After starting the proxy, call caps.proxy_only(proxy) and pass proxy.sandbox_env() to sandboxed_exec().

load_embedded_policy

Parse the bundled policy JSON and return it as a Policy.

Example


Import

All functions are available from the top-level module: