Overview
Network rules control TCP bind and connect operations. Like filesystem rules, they follow an allow-list model: any network operation not explicitly allowed is denied.Rule Format
Network rules use the format:- RIGHTS: What network operations are allowed (bind, connect, or both)
- PORT: The TCP port number (0-65535)
Adding Rules
Network Rights
All available network rights:Allow binding (listening) on a TCP port. Use for servers and local services.Allowed operations:
bind()system call on the specified port- Listen for incoming connections
- Accept connections
Bind permission does not include connect permission. Use
bc for both.Allow connecting (outbound) to a TCP port. Use for HTTP clients, API calls, database connections.Allowed operations:
connect()system call to the specified port- Establish outbound TCP connections
Allow both binding and connecting on a TCP port.Allowed operations:
- All
bindoperations - All
connectoperations
The shorthand
bc can also be written as cb - both are equivalent.Port Specification
Ports must be specified as integers between 0 and 65535:Kernel Requirements
Network rules require specific kernel versions:| Feature | Landlock ABI | Minimum Kernel | Notes |
|---|---|---|---|
| TCP bind restrictions | v4+ | 6.7+ | Control bind() syscall |
| TCP connect restrictions | v4+ | 6.7+ | Control connect() syscall |
Checking Compatibility
To verify your kernel supports network rules:With
--best-effort, sandboxec will skip network rules on kernels that don’t support them, applying only filesystem restrictions.Common Patterns
Outbound HTTPS Only
Allow only secure outbound connections:HTTP and HTTPS Client
Allow both HTTP and HTTPS:Local Development Server
Bind a local port for testing:API Service with Outbound Calls
Server that also makes outbound requests:Database Client
Connect to a database server:Real-World Examples
Rule Behavior
Allow-List Model
Cumulative Rules
Multiple--net flags are cumulative:
Port-Specific Rules
Each rule applies to a specific port number:No Wildcard Ports
sandboxec does not support wildcard or port range rules. Each port must be explicitly specified.
Combining with Filesystem Rules
Network rules are almost always used with filesystem rules:Troubleshooting
Connection refused or Operation not permitted
Connection refused or Operation not permitted
Ensure the target port is allowed:
Cannot bind: Address already in use
Cannot bind: Address already in use
This is a normal OS error, not a sandboxec restriction. Another process is using the port:
Network rules not working on old kernel
Network rules not working on old kernel
Network rules require kernel 6.7+. Check your version:Use
--best-effort to skip unsupported features:DNS resolution fails
DNS resolution fails
DNS typically uses UDP, which Landlock does not control. If DNS fails, it’s likely a filesystem issue (missing
/etc/resolv.conf or libraries):Wrong rights: bind instead of connect (or vice versa)
Wrong rights: bind instead of connect (or vice versa)
Verify you’re using the correct rights:
cfor outbound connections (clients)bfor inbound connections (servers)bcfor both