Customize Sandbox Policies
Use this page to apply and iterate policy changes on running sandboxes. For a full field-by-field YAML definition, use the Policy Schema Reference.
Policy Structure
A policy has static sections filesystem_policy, landlock, and process that are locked at sandbox creation, and a dynamic section network_policies that is hot-reloadable on a running sandbox.
Static sections are locked at sandbox creation. Changing them requires destroying and recreating the sandbox.
Dynamic sections can be updated on a running sandbox with openshell policy set and take effect without restarting.
Baseline Filesystem Paths
When a sandbox runs in proxy mode (the default), OpenShell automatically adds baseline filesystem paths required for the sandbox child process to function: /usr, /lib, /etc, /var/log (read-only) and /sandbox, /tmp (read-write). Paths like /app are included in the baseline set but are only added if they exist in the container image.
This filtering prevents a missing baseline path from degrading Landlock enforcement. Without it, a single missing path could cause the entire Landlock ruleset to fail, leaving the sandbox with no filesystem restrictions at all.
User-specified paths in your policy YAML are not pre-filtered. If you list a path that does not exist:
- In
best_effortmode, the path is skipped with a warning and remaining rules are still applied. - In
hard_requirementmode, sandbox startup fails immediately.
This distinction means baseline system paths degrade gracefully while user-specified paths surface configuration errors.
Apply a Custom Policy
Pass a policy YAML file when creating the sandbox:
openshell sandbox create keeps the sandbox running after the initial command exits, which is useful when you plan to iterate on the policy. Add --no-keep if you want the sandbox deleted automatically instead.
To avoid passing --policy every time, set a default policy with an environment variable:
The CLI uses the policy from OPENSHELL_SANDBOX_POLICY whenever --policy is not explicitly provided.
Iterate on a Running Sandbox
To change what the sandbox can access, pull the current policy, edit the YAML, and push the update. The workflow is iterative: create the sandbox, monitor logs for denied actions, pull the policy, modify it, push, and verify.
The following steps outline the hot-reload policy update workflow.
-
Create the sandbox with your initial policy by following Apply a Custom Policy above (or set
OPENSHELL_SANDBOX_POLICY). -
Monitor denials. Each log entry shows host, port, binary, and reason. Alternatively, use
openshell termfor a live dashboard. -
Pull the current policy. Strip the metadata header (Version, Hash, Status) before reusing the file.
-
Edit the YAML: add or adjust
network_policiesentries, binaries,access, orrules. -
Push the updated policy. Exit codes: 0 = loaded, 1 = validation failed, 124 = timeout.
-
Verify the new revision. If status is
loaded, repeat from step 2 as needed; iffailed, fix the policy and repeat from step 4.
Global Policy Override
Use a global policy when you want one policy payload to apply to every sandbox.
When a global policy is configured:
- The global payload is applied in full for all sandboxes.
- Sandbox-level policy updates are rejected until the global policy is removed.
To restore sandbox-level policy control, delete the global policy setting:
You can inspect a sandbox’s effective settings and policy source with:
Debug Denied Requests
Check openshell logs <name> --tail --source sandbox for the denied host, path, and binary.
When triaging denied requests, check:
- Destination host and port to confirm which endpoint is missing.
- Calling binary path to confirm which
binariesentry needs to be added or adjusted. - HTTP method and path (for REST endpoints) to confirm which
rulesentry needs to be added or adjusted.
Then push the updated policy as described above.
Examples
Add these blocks to the network_policies section of your sandbox policy. Apply with openshell policy set <name> --policy <file> --wait.
Use Simple endpoint for host-level allowlists and Granular rules for method/path control.
Simple endpoint
Granular rules
Allow pip install and uv pip install to reach PyPI:
Endpoints without protocol use TCP passthrough, where the proxy allows the stream without inspecting payloads.
Query parameter matching
REST rules can also constrain query parameter values:
query matchers are case-sensitive and run on decoded values. If a request has duplicate keys (for example, tag=a&tag=b), every value for that key must match the configured glob(s).
Next Steps
Explore related topics:
- To learn about network access rules and sandbox isolation layers, refer to Index.
- To view the full field-by-field YAML definition, refer to the Policy Schema Reference.
- To review the default policy breakdown, refer to Default Policy.