Skip to content

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.

  • A clone of the Zentri repository and the Go toolchain. The templates are compiled into zentri, so a change means a rebuild.
  • A working openshell session setup: an OpenShell v0.1.10 gateway, the openshell CLI, and the sandbox image for your agent. See sandboxing.
  • Optional: the openshell v0.1.10 CLI on your PATH, so the check can run openshell policy lint. It works offline.

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/zentri only, on /v1/**, /mcp, and GET /healthz. The hooks, the MCP server, and the heartbeat are all that binary. /metrics is 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/git only. It is present only when the repository’s origin is an https or http URL.

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/zentri

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.

Terminal window
ls sandbox/openshell/policies/
claude-code.yaml
codex.yaml
opencode.yaml
policies_test.go
policies.go
README.md
stub.yaml

Each template starts with comments that name the agent version and the sources for its hosts. Read them before you change a vendor 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/claude

The 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 refuse protocol: tcp and enforcement: audit.
  • Name the narrowest binary. A binary path must be the real file, not a symlink, because OpenShell matches the real path.
  • Prefer rules with methods and paths over access: 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 zentri needs 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.

Terminal window
scripts/check-openshell-policies.sh

The 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:

Terminal window
go test ./sandbox/...
ok zentri.dev/zentri/sandbox/openshell/policies 0.132s

make lint runs the script too, along with every other linter.

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:

Terminal window
make sandbox-image AGENT=claude-code

This runs make build-go first. Use the new bin/zt, and check which image it will start:

Terminal window
bin/zt sandbox image claude-code
zentri-agent-claude-code:49d9698

The tag is your build’s version.

Terminal window
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.

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.

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.
  • No runtime setting overrides a template. Every change means editing the repository and rebuilding zentri and the image.
  • Git over SSH is not allowed. A tcp endpoint cannot set enforcement, and every endpoint must have it.
  • A rest endpoint 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, and zentri. 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-openshell passed 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.