Writing OpenShell policies
A session started with --launcher openshell runs its agent in an OpenShell sandbox. A policy decides what the agent can read, write, and reach on the network. Zentri ships one policy template per agent and fills it in at each zt start. This guide shows what a template says, how to change one, and how to check the change before a sandbox uses it.
The design is in ADR-0004 and ADR-0008 in the Zentri repository, under docs/adr/. The templates and their notes are in sandbox/openshell/policies/.
Every user brings their own agent credentials. Zentri never collects, proxies, stores, or resells model access or consumer subscription tokens. In a sandbox, the credential comes from the OpenShell providers you name in ZENTRI_OPENSHELL_PROVIDERS, which OpenShell holds.
Before you start
Section titled “Before you start”- A clone of the Zentri repository and the Go toolchain. The templates are compiled into
zentri, so a change means a rebuild. - A working
openshellsession setup: an OpenShell v0.1.10 gateway, theopenshellCLI, and the sandbox image for your agent. See sandboxing. - Optional: the
openshellv0.1.10 CLI on yourPATH, so the check can runopenshell policy lint. It works offline.
What a policy says
Section titled “What a policy says”There is one template per agent kit. zt start picks it from the agent command’s base name.
| Agent command | Template | Vendor hosts allowed |
|---|---|---|
claude |
claude-code.yaml |
api.anthropic.com, claude.ai, claude.com, platform.claude.com |
codex |
codex.yaml |
api.openai.com, chatgpt.com (/backend-api/** only), auth.openai.com |
opencode |
opencode.yaml |
api.anthropic.com, api.openai.com |
zentri-stub-agent |
stub.yaml |
none; the scripted test agent |
Every template has the same sections:
| Section | What it says |
|---|---|
filesystem_policy |
/usr, /lib, /etc, and /opt are read-only. /sandbox, /tmp, /var/lib/zentri, /dev/pts, and /dev/ptmx are read-write. The kit and its hooks live under /etc, so the agent cannot remove them. |
landlock |
compatibility: hard_requirement. A kernel without Landlock fails the sandbox instead of running it unconfined. |
process |
The agent runs as uid and gid 1000. OpenShell rejects root. |
network_policies |
Egress is denied unless a rule allows it. Each rule names endpoints and the binaries that may use them. |
The network rules:
zentri_coordinator: the coordinator, for/usr/local/bin/zentrionly, on/v1/**,/mcp, andGET /healthz. The hooks, the MCP server, and the heartbeat are all that binary./metricsis not allowed.- The vendor rule: the agent’s hosts on port 443, for the agent binary only. A rule also covers the processes that the binary starts, so commands the agent runs can reach its vendor too.
git_remote: fetch and push of one repository over HTTPS, for/usr/bin/gitonly. It is present only when the repository’soriginis anhttpsorhttpURL.
Every endpoint uses protocol: rest and enforcement: enforce, so OpenShell reads each request and blocks one that breaks a rule. Here is the coordinator rule from codex.yaml:
zentri_coordinator: name: zentri-coordinator endpoints: - host: "@COORDINATOR_HOST@" port: @COORDINATOR_PORT@ protocol: rest enforcement: enforce rules: - allow: { method: "*", path: "/v1/**" } - allow: { method: "*", path: "/mcp" } - allow: { method: GET, path: "/healthz" } binaries: - path: /usr/local/bin/zentriPlaceholders
Section titled “Placeholders”zt start fills these in, then writes the policy to a private temp file and passes it to openshell sandbox create --policy. The temp file is removed after the launch.
| Placeholder | Becomes |
|---|---|
@COORDINATOR_HOST@, @COORDINATOR_PORT@ |
The coordinator as the sandbox reaches it. A loopback URL becomes host.openshell.internal. |
@GIT_HOST@, @GIT_PORT@, @GIT_PATH@ |
The origin remote, such as github.com, 443, and /org/repo.git. |
# @GIT_BEGIN@ … # @GIT_END@ |
The lines between are kept when origin fits a git rule, and dropped otherwise. |
Rendering refuses a host that is not a lowercase DNS name, a port out of range, a git path with a glob or a .. segment, and any placeholder left unfilled.
1. Find the template
Section titled “1. Find the template”ls sandbox/openshell/policies/claude-code.yamlcodex.yamlopencode.yamlpolicies_test.gopolicies.goREADME.mdstub.yamlEach template starts with comments that name the agent version and the sources for its hosts. Read them before you change a vendor rule.
2. Add a rule
Section titled “2. Add a rule”Say Claude Code should read an internal docs site with its web fetch tool. Add a rule under network_policies in claude-code.yaml, outside the git markers:
internal_docs: name: internal-docs endpoints: - host: docs.example.internal port: 443 protocol: rest enforcement: enforce rules: - allow: { method: GET, path: "/**" } binaries: - path: /usr/local/bin/claudeThe rules for any change:
- Write each endpoint in block style, starting with
- host:. The check cannot read an endpoint written as one{ ... }line. - Give every endpoint
enforcement: enforce. The Go tests refuseprotocol: tcpandenforcement: audit. - Name the narrowest binary. A binary path must be the real file, not a symlink, because OpenShell matches the real path.
- Prefer
ruleswith methods and paths overaccess: full. - Keep the SPDX header in the first 5 lines, and keep exactly one
# @GIT_BEGIN@and one# @GIT_END@. - Do not widen the coordinator rule. Only
zentrineeds it.
filesystem_policy, landlock, and process are pinned by the Go tests in policies_test.go. Change them only if you also change the tests and the images, which expect these paths and uid 1000.
3. Check the template
Section titled “3. Check the template”scripts/check-openshell-policies.shThe script renders each template twice, with and without the git rule, the same way zt start does. It fails on a missing SPDX header, a placeholder left over, a missing network_policies section, an endpoint without enforcement: enforce, or an endpoint in flow style. Without the openshell CLI it prints:
OpenShell policies are enforced. openshell is not on PATH, so policy lint was skipped.With openshell on PATH, or its path in OPENSHELL_BIN, it also runs openshell policy lint on each rendered policy and prints:
OpenShell policies are enforced and pass <openshell --version> policy lint.Then run the Go tests, which render every template through the same code zt start uses:
go test ./sandbox/...ok zentri.dev/zentri/sandbox/openshell/policies 0.132smake lint runs the script too, along with every other linter.
4. Rebuild zentri and the image
Section titled “4. Rebuild zentri and the image”The templates are embedded in the zentri binary, so rebuild it. The sandbox image tag comes from the zentri version, which is git describe --tags --always --dirty. An edited or new commit changes the version, so rebuild the image as well:
make sandbox-image AGENT=claude-codeThis runs make build-go first. Use the new bin/zt, and check which image it will start:
bin/zt sandbox image claude-codezentri-agent-claude-code:49d9698The tag is your build’s version.
5. Start a session
Section titled “5. Start a session”bin/zt start --launcher openshell --agent claude "summarize the deploy runbook"The new policy applies to sandboxes created from now on. A running sandbox keeps the policy it was created with.
Running sandboxes
Section titled “Running sandboxes”Zentri never changes a running sandbox’s policy. OpenShell v0.1.10 can reload the network rules of a running sandbox with openshell policy update or openshell policy set --wait. The filesystem, Landlock, and process sections need a new sandbox. Zentri’s sandboxes are named zentri- and the last 8 characters of the session ID. Zentri has not tested a policy change on a live sandbox, and the next zt start uses the template again.
What can go wrong
Section titled “What can go wrong”| Message | Cause and fix |
|---|---|
... endpoint ... has no enforcement: enforce |
An endpoint lacks the line. Add it. |
write endpoints in block style so this check can read them |
An endpoint is written as - { host: ... }. Rewrite it in block style. |
missing SPDX-License-Identifier in the first 5 lines |
The header was moved or removed. |
placeholder left after rendering |
A new @NAME@ that Zentri does not fill. Remove it. |
openshell policy lint failed |
OpenShell refused the rendered policy. The lines after it say why. |
policy <kit>: git markers are not one begin and one end |
A marker was removed or repeated. |
zentri: the sandbox gets no rule for git remote origin: ... |
origin did not fit a git rule, for example a path with a glob. The session still starts, without git egress. Work comes home through zt done either way. |
openshell has no sandbox image for agent "..." |
Only claude, codex, opencode, and zentri-stub-agent have a template and an image. |
| The sandbox fails to start after a rebuild | The image for the new version tag is missing. Run make sandbox-image AGENT=<kit>. |
| The agent still cannot reach the new host | The binary path in the rule is a symlink or the wrong binary, or the client opens a WebSocket, which a rest endpoint refuses with 403. |
Limitations
Section titled “Limitations”- No runtime setting overrides a template. Every change means editing the repository and rebuilding
zentriand the image. - Git over SSH is not allowed. A
tcpendpoint cannot setenforcement, and every endpoint must have it. - A
restendpoint refuses a WebSocket upgrade with 403. Codex must use its HTTP transport. - Agents cannot ask for a new host. ADR-0004 plans network approvals through decisions. They are not built.
- The images hold only the agent,
git,tmux,ca-certificates, andzentri. A rule for a package registry does nothing unless the image has the tool that uses it. - The only real sandbox runs used the stub agent:
make e2e-openshellpassed on macOS 15.7.9 arm64 with Docker Desktop 29.3.0 and in CI on Ubuntu. No real Claude Code, Codex, or OpenCode has run in a sandbox.