The agent path: relay and jail
This is the part of p0ssess that hands multi-step work on files to another model. Claude Code starts the p0ssess relay subagent, the subagent calls the p0ssess MCP server, and the MCP server runs the task in a jailed OpenCode server that talks to OpenRouter.
On this page
Claude Code (main model)
└─ Agent(subagent_type="p0ssess:p0ssess") background by default; SendMessage continues it
└─ p0ssess agent on Haiku tools: the routed p0ssess MCP tools, nothing else
└─ p0ssess mcp (stdio) run / wait / abort / answer_permission / models
└─ pod p0ssess-<random> one per relay session, rootless podman
├─ <pod>-server opencode serve 2.2.5
├─ <pod>-proxy holds the OpenRouter key, forwards to openrouter.ai
└─ <pod>-egress only with shell internet: the shell's proxy to public addresses
Status: built, tested and shipped in the plugin. The relay tools live on the plugin's one MCP server next to the direct and engine tools; inside the plugin their names are mcp__ and the agent is p0ssess:p0ssess. Each run's start and end are reported to the engine: the status line counts it as running, and its measured cost becomes spend.
Pinned versions
| Piece | Version | Check |
|---|---|---|
| OpenCode | 2.2.5, opencode-linux-x64.tar.gz |
SHA-256 09f44302…2a79614e (the release's published digest) and binary SHA-256 8d060e1d…23a92050, both checked by p0ssess jail build |
| Base image | registry.fedoraproject.org/ |
pinned by digest |
| OpenCode API | internal/ |
the contract test checks every operation and field the client uses |
The client refuses any server that does not report version 2.2.5. To upgrade OpenCode: add the new spec next to the old one, run the contract test against it, record a new event stream, and add the version to SupportedVersions.
Where it runs
Each agent session runs in one of two places: the local jail (rootless podman on this machine) or the hosted cloud sandbox (Pro and Team). The choice is the sandbox.where setting, one of auto (the default), local or cloud. Set it in plain words ("run agent jobs in the cloud") through settings_, or in budget.toml under [sandbox] as where. P0SSESS_ overrides it for tests and development, and sandbox in config.json is the last fallback.
| Setting | Linux with rootless podman | macOS, Windows, Linux without podman |
|---|---|---|
auto |
local | cloud for Pro and Team, otherwise the plain line below |
local |
local | the job does not run; it says so |
cloud |
cloud for Pro and Team | cloud for Pro and Team |
A missing jail image does not move a job to the cloud; the image is built as before.
A Free install that needs a sandbox it does not have gets one line instead of a failure: This job needs a sandbox, and it can run in the p0ssess cloud sandbox with Pro (/ (On Linux it says install rootless podman.) Read-only work keeps running on the direct path. The offer counts as upgrade_ only when the user opted in to usage counts.
The queue. The hosted sandbox runs a fixed number of sessions at once. When all are busy, the host queues the request (first in, first out, one place per account, accounts that just ran go behind others, at most 16 waiting) and answers with a place and an estimate from the durations of recent sessions. The client keeps the request alive, writes the place to sandbox-queue.json in the state directory, and the status line shows queued 2nd, ~4 min (just queued 2nd until the host has enough finished sessions to estimate). When a slot frees up it is held for the head of the queue and the session starts at once. The wait is capped by sandbox.wait_ (default 10); past it the request is withdrawn with The cloud sandbox stayed busy for 10 min, so this job was not started. Try again in a while, or say "wait longer for the cloud sandbox" to raise the limit.
Hours. Pro and Team include 20 cloud sandbox hours a month (session wall time, counted per calendar month in UTC). When they are used up the host answers with This month's sandbox hours are used up (20h of 20h). and the client adds that they come back on the 1st. The p0ssess page and / show 3h used, 17h left this month.
The jail
Every relay session gets its own jail. The first run of a session creates it, follow-ups in the same session reuse it, and it is removed when the session ends (see Session lifetime). Nothing is shared between sessions: not the server, not OpenCode's database, not a worktree, not a volume. A cold jail starts in about 0.65 seconds (0.75 with shell internet) and is removed in about 0.2 seconds; see Tests for the measurement.
A jail is:
-
A pod with
--userns=keep-id(files written in the jail belong to you) and one published port, a random free127.0.0.1port → 4096. Its password is 32 random bytes in the jail's record directory (<state>/, mode 0600). Its labels tie it to the state directory that holds its record, so a sweep only ever looks at its own jails.relay/ jails/ <pod>/ pw -
An egress filter in the pod's network namespace. nftables rules are loaded from outside (
podman unshare nsenter -t <infra pid> -n nft -f -) after the pod starts and before anything else runs in it, so nothing inside the pod can change them. Rejected destinations:0/,8 10/,8 100.64/(Tailscale),10 127/off loopback,8 169.254/(includes pasta's host mapping, 169.254.1.2),16 172.16/,12 192.168/, multicast and broadcast; IPv616 ::1,fc00::/(includes7 fd00::/and Tailscale's8 fd7a:115c:a1e0::/),48 fe80::/,10 ff00::/; any global prefix the host itself is on; and any range in8 blocked_incidrs config.json. The only allowed link-local destination is pasta's DNS forwarder, 169.254.1.1 port 53. Everything else (the internet) is allowed for the server itself. The relay checks that the table is present before every run and refuses to run without it. -
The proxy container. It runs
p0ssess proxyfrom the host binary (mounted read-only) and is the only place the OpenRouter key exists. It forwards/toapi/ v1/ * https://, replaces theopenrouter.ai Authorizationheader, and setsprovider.data_tocollection "deny"on every request that names a model, plusprovider.zdr = truewhen the budget's privacy mode iszdr(--zdr; a session started without it cannot continue once the mode is turned on). Compressed request bodies are refused, so the rule cannot be bypassed. It also refuses every request after a deadline the relay writes for it: the run's maximum runtime after each prompt, and one minute after the run ends. A run whose relay process died therefore stops spending at its maximum runtime, even though nothing interrupts it. Its log lists method, path, model and status, never bodies. -
The egress container, only when the user turned on shell internet for the project.
-
The server container. It runs
opencode serve. Read-only root filesystem,--cap-drop ALL,no-new-privileges, a 2048 process limit, a private/, and a privatetmp /(OpenCode's database) on a tmpfs, so the session's transcript lives only as long as its jail. Its OpenRouter key is a placeholder; its base URL points at the proxy. Mounts:state - the repository, read-only, at its host path, so session directories and Claude's paths agree;
- empty read-only tmpfs mounts over
<repo>/and.p0ssess <repo>/, which hide every other session's worktree and git admin directory;.git/ worktrees - for an edit session, its own worktree
<repo>/and its admin directory.p0ssess/ wt/ <name> <repo>/, read-write, on top of those..git/ worktrees/ <name>
Nothing else from your home directory is mounted, and the container has no SSH keys or credentials. A read session has nothing writable under the repository.
Where a run works (since 1.1): the repository holding the first path the task names, else the repository of the run's directory (
cwdwhen the caller passes it, else the Claude Code session's working directory as its status line and hooks recorded it, elseCLAUDE_), else a repository near it whose name the task uses. Every other repository the task names, directly or in a small text file it names (a spec), is mounted too, up to three, each with its own worktree in edit mode. Nothing is refused for want of a repository: read-only work then runs on the direct path with the files it names, edit work in a scratch repository holding copies of them; changed copies go back over their originals, and new files go to the directory the task names ("write notes.md in /tmp/x"), never over an existing file. A repository is never mounted when it is the root, your home directory or a directory above it, hasPROJECT_ DIR .ssh,.gnupg,.config,.aws,.azure,.kube,.docker,.password-store,.netrc,.git-credentialsor.pgpassat its top, or holds (or sits inside) p0ssess's config, cache or state directory or the OpenRouter key file.jail.Startrepeats the check, so no caller can mount such a directory.
Security: a directory outside a repository was mounted (fixed in 0.5.4)
Affected: every version with the agent path, 0.1.0 through 0.5.3. Fixed in 0.5.4. Upgrade. The direct path (video, audio, images) mounts nothing and was not affected.
The bug. The relay mounts the run's repository into the jail. When the run's directory was not inside a git repository, it used the directory itself as the repository. The p0ssess agent does not pass cwd, so the directory was Claude Code's project directory. Starting Claude Code in your home directory and asking for agent work therefore mounted your whole home directory read-only into the server container. Any other directory outside a repository was mounted the same way. Edit mode was refused there (it needs a .git directory), so only read sessions were affected, unless the directory was itself a git repository, as a home directory managed with git can be.
Impact. The mount was read-only, and a read session cannot edit files, so nothing was changed. Inside the mounted directory the model could read every file you can read: through its read, glob and grep tools (the read tool's denies cover only .ssh/, .env, .env.* and .envrc) and through the read-only shell commands a read session allows, such as cat, which those denies do not cover. That includes SSH private keys, cloud and service tokens under .config, and p0ssess's own OpenRouter key file when it is in the default place (~/). The key proxy keeps the key out of the server container's environment and memory; it does not help when the key file itself is mounted, so in this case the key was readable by the model like any other file. Whatever the model read went into its context, which is sent to the OpenRouter provider serving the run, and could appear in the answer returned to Claude Code. There was no automatic way to send files anywhere else: the shell has no network unless you turned on shell internet for that directory (and then only public addresses on ports 80 and 443, through commands a read session must ask for), and webfetch asks first. The egress filter, the jail's other limits and the per-run cost cap applied as usual.
Check whether you were affected. Each agent session's record names its repository: grep -h '"repo"' ~/ (0.4.0 and later; with P0SSESS_ set, $P0SSESS_). A repo that is your home directory, or any directory that is not a git repository, means that directory was mounted for that session. If a run in such a session reached the model, treat the files in that directory as shown to that run's provider: rotate the OpenRouter key and any credentials stored there.
Session lifetime
| When | What happens to the jail |
|---|---|
a session's first run |
created (the worktree first, for edit mode), then the OpenCode session |
a follow-up run with session (Claude's SendMessage to the relay agent) |
reused; it is verified (all containers running, egress filter loaded) before every prompt |
| a run ends | an idle timer starts: session_ in config.json, default 1800 (30 minutes); the key proxy refuses model calls from a minute after the run until the next prompt |
| the idle timer fires with no new run | removed; the session is marked ended, and a later wait returns its last result while a later run says "has ended; start a new run" |
| the Claude Code session ends (the MCP server's stdin closes) | runs still active are interrupted and recorded, then every jail the server owns is removed |
| the p0ssess process is killed or crashes | the jail outlives it; the next p0ssess start (the MCP server, any relay command, or p0ssess jail sweep) removes every jail whose owner is gone |
p0ssess run from a shell |
the jail is removed when the run ends, unless --keep keeps it for session_ so p0ssess run --session can continue it; with --detach, or a run paused on a permission request, it is kept until the run's maximum runtime plus session_ |
A jail's record names the process that owns it (pid and start time, so a reused pid does not count). A sweep removes a jail whose owner is gone, unless it was detached on purpose, and then only once its keep time has passed. A wait or answer from another process adopts a detached jail. Pods with no record and records with no pod are removed after two minutes, so a jail another process is still creating is left alone. p0ssess 0.3's shared per-repository pods and their -state volumes are not touched automatically: remove them with p0ssess jail sweep --legacy once no 0.3 process runs.
OpenCode configuration
The jailed server gets its global config through OPENCODE_; project config files and Claude Code skill folders are ignored (OPENCODE_, OPENCODE_). The config:
- Policies (hard denies that OpenCode applies after every agent and session rule, so an allow-all session cannot undo them):
sudo,su,doas,pkexec,runuser,ssh,scp,sftp,rsync,sshpass,git push(includinggit <opts> push),docker,podman,buildah,nerdctl,kubectl,systemctl,loginctl,nsenter,unshare,chroot, baresh,bash,bash -c(and-lc,-ec…),zsh,dash,fish,ksh,eval,exec,rm -rf /; edits to.git,.git/,* .ssh,.ssh/,* .env,.env.*,.envrcand reads of.ssh/,* .env*, each in both relative (x/) and absolute (* */) form; reads of any absolute path (x/ * read:/, with* /andproc/ * /spelled out), which blocks every literal read outside the worktree,state* /and the server'sproc/ 1/ environ /among them, since in-worktree reads carry a relative resource; webfetch to every loopback, link-local and private host (state 127.*,localhost,[::1],169.254.*,10.*,192.168.*,172.*,100.*, both schemes), which fences the loopback API and the key proxy from the one in-process tool that could otherwise reach them;external_everywhere; every provider exceptdirectory openrouter; every MCP server. - The shell is the jail wrapper, not
/.bin/ sh shellpoints at the hostp0ssessbinary (mounted read-only at/). See "The jailed shell" below.opt/ p0ssess formatterandlspare off. Both run repository-controlled programs inside the server process (a formatter on save, a language server on open); neither was asked for.- The title agent is disabled. OpenCode would otherwise send each first prompt to the provider's "small" model, which nobody chose.
sharedisabled, updates disabled.- The run's model is declared under
providers.openrouter.models, with its context, prices and an output limit sized from the run's cap. OpenCode 2.x runs only models in its catalog, a models.dev snapshot built into the binary that the jail never refreshes, and an undeclared id newer than the snapshot fails with "Model unavailable"; a declared one joins the catalog. The declared limit is what OpenCode sends asmax_, and the key proxy lowers every call's limit further to what is left of the cap. A continued session cannot switch to a model its jail was not started with when OpenCode's catalog lacks it; start a new run.completion_ tokens
OpenCode splits pipelines before matching, so curl … | sh is stopped by the bare-shell rules, not by a pipe pattern.
The jailed shell
OpenCode takes its shell from config and runs <shell> -c <command>, so shell: / makes every command the model runs pass through the host binary's -c wrapper (internal/) instead of a plain /. For each command the wrapper:
- Scrubs the environment. It drops
OPENCODE_,* P0SSESS_and anything whose name contains* KEY,TOKEN,SECRET,PASSWORD,PASSWDorCREDENTIAL, soecho $OPENCODE_and the proxy's variables yield nothing, and pointsPASSWORD HOME/TMPDIRat the writable/(becausetmp /is masked, below).state - Enters fresh user, network, mount and pid namespaces (
unshare -U -r -n -m -p --fork). The new network namespace has nothing but a loopback interface, so the OpenCode API, the key proxy, the LAN and the internet are unreachable from a command. The new user namespace makes/(the server's own environment) unreadable and blocks ptrace of the server; the cross-user-namespace denial is checked empirically by the integration test. In the new mount namespace it overmountsproc/ 1/ environ /with an emptystate tmpfs, so a command sees an empty/and cannot touch the session's database. The mounts it inherits from the server are locked together by the kernel, so a command cannot unmount the masks over other sessions' worktrees (tested).state - With shell internet only, starts a forwarder inside the command's namespaces and sets
HTTP_/PROXY HTTPS_(below).PROXY
Without shell internet, commands have no network: pip, npm and go module downloads fail. That is the default. Offline, vendored builds and tests still work (the integration test adds a function and runs python3 -m unittest inside the jail). The whole mechanism depends on the repository mounts carrying the shared SELinux label (:z, the default); with selinux: disable the containers run with label=disable instead, which is weaker and not recommended.
Shell internet
Off by default. The user turns it on per project, in their own budget.toml only ([sandbox] shell_, set through settings_ with sandbox.shell_, /, or by asking Claude, which needs the user's yes at the tool's permission prompt). A repository's own .p0ssess/ cannot turn it on; project scope only tightens. It is fixed when a session's jail starts: a session started with it cannot continue after the user turns it off. Every result of such a session says shell_ with a note, and the relay agent's metadata line ends with shell internet: on, so it is never on quietly.
How it works, without loosening anything else:
- The jail gets one more container,
<pod>-egress, runningp0ssess egresswith the same confinement as the others (read-only root, no capabilities,no-new-privileges, no key). It listens on a Unix socket in a directory shared, read-only for the server, between the two containers. It is an HTTP proxy forCONNECTand absolutehttp://requests. It resolves each name itself and connects only to public unicast addresses on ports 80 and 443. The check runs on the resolved address the socket is about to connect to, so a name that resolves to a private address is refused too. Refused: loopback (the OpenCode API and the key proxy),0/,8 10/,8 100.64/,10 169.254/,16 172.16/,12 192.168/, the documentation, benchmarking, reserved and 6to4/Teredo/NAT64 ranges, multicast, IPv6 loopback, ULA (16 fc00::/, including Tailscale), link-local, the host's own prefixes and7 blocked_. The refusal says only "destination refused", so a command cannot learn whether an internal name exists. It runs in the pod's network namespace, so the nftables filter is a second fence behind it.cidrs - The wrapper starts a forwarder inside the command's own namespaces: it brings the namespace's loopback up, listens on
127.0.0.1:3128, and relays to the socket. A Unix socket is a file, not a network endpoint, so it is the namespace's only way out, and only to the proxy. Tools that honorHTTP(S)_(pip, npm, go, cargo, git over HTTPS, curl, Python's urllib) work; anything that resolves names itself or opens raw sockets has no route at all.PROXY - In edit mode the session rules also allow
pip install,npm install/ci,go mod download/tidy,go get,cargo fetch,git fetch/cloneandcurl; without shell internet they keep asking.
The integration test proves it in a real jail: a public HTTPS fetch works with the opt-in and fails without it; the API and the key proxy (by address and as localhost), the LAN targets from P0SSESS_ (on their own port, 80 and 443), Tailscale's addresses, pasta's host mapping and every address of the host are all refused through the proxy; direct connections to anything have no route; and the proxy, server and egress containers run unprivileged with a read-only root, no added capabilities and no-new-privileges.
What it does not cover: a router that forwards ports from the network's public address back into the LAN (hairpin NAT) makes that public address a way back in. Add it to blocked_ in config.json if that applies. Name resolution goes through the host's resolver, so the resolver sees the names a command asks for.
Per-session rules
Rules are set when the relay creates a session. The last matching rule wins, so each list starts with a catch-all * * ask:
| read mode | edit mode | |
|---|---|---|
| read, glob, grep, todo | allow | allow |
| edit | deny | allow (inside the worktree; policies still protect .git, .ssh, .env) |
| shell | allowlist of read-only commands (ls, cat, rg, git status/, and the checks models run to orient themselves: id, true, test, printf, nl, sha256sum, mount, findmnt …), anything else asks |
the same plus writing and the project's own build and test commands (python3, pytest, go test, npm test, npx jest, cargo test, mvn test, dotnet test, make, ./, mkdir, touch, mv, rm, sed, git add/, git -C <dir> status/ …), plus fetch and install commands with shell internet; anything else asks |
| webfetch, websearch | ask | ask |
| question, subagent, skill, image generation, external directories | deny | deny |
Edit mode already runs the project's code, so allowing its test runners and in-tree writes widens nothing; the jail is the boundary. What still asks or is denied: network fetches and installs without shell internet, env/printenv, anything not listed; the global policies deny sudo, ssh, nested shells, container tools, git push and writes to .git, .ssh and .env; the repository itself is mounted read-only and other directories are denied. Each task also gets a short note (see Task orientation) so models stop probing.
Task orientation
Claude names paths in the repository, but an edit run works in a worktree (a cloud run under another root) where the repository is read-only or absent. In the 2026-11-13 savings benchmark cheap models spent edit runs testing mounts and write access and stopped for permission. So before sending, the relay rewrites paths under the repository root to the copy the model works in (not paths already under .p0ssess/), and appends a note: where the copy is, that changes are collected without committing, that the project's tests may be run, and that the run ends with a short report (each file changed, the test command and its counts, no file contents or diff). A read run's note says it is read-only and not to probe.
An ask in read mode is rejected at once with feedback ("not allowed in this delegated read-only task … continue without it"), and the model carries on. An ask in edit mode pauses the run and comes back to Claude as needs_. The relay answers only once or reject; always is refused, because it would save a project-wide allow rule. A request nobody answers for permission_ (config.json, default 1800) is rejected, the run is stopped with that reason in its note, and its jail is removed. From a shell, p0ssess answer --session S --request R --decision once|reject and p0ssess abort --session S make the same calls as the tools; the plugin's hook points to them when the p0ssess agent type is not available in a session. abort on a paused run reports interrupted, not needs_.
The MCP tools
| Tool | Does |
|---|---|
run |
task, model (OpenRouter id; optional, see below), mode (read default, or edit), cwd (default CLAUDE_), attachments (file paths), session (continue), kind (for the history), wait_. Blocks until the run ends, pauses on a permission request, or wait_ passes (default 25 minutes). |
wait |
Keeps blocking on a session that returned still_. |
abort |
Interrupts a session. |
answer_ |
once or reject for a paused edit task, then blocks like wait. |
models |
Models with context, price per million tokens and modalities, from the route table's model facts (or P0SSESS_, or registry_ in the config) or, with live: true, from OpenRouter. |
Results are JSON with answer first, then status (done, failed, interrupted, needs_, still_, tampered), session_, model, mode, cost_, tokens, duration_, transcript_, shell_ when it was on, jail_ on a session's first run, and for edit mode worktree, diff_, diff_ and apply (the git -C <repo> apply <diff_ command). The patch itself is not in the result (the agent passes on its path, so it only cost tokens), and an edit run's answer is capped at 4,000 characters (the model is asked for a short report: files changed and the test command with its counts; the full text stays in the run directory).
Since 1.1 run also heals and checks what it can before anything reaches the caller. Work that needs current information (news, prices, the last few months) goes to the direct path with OpenRouter's web search plugin (about $0.02 a call, in the estimate); an edit task gathers that data first and passes it to the sandboxed run. A missing jail image is built, a model the sandbox reports unavailable or whose provider fails gives way to the next option the engine ranked inside the limits (all of them are declared to OpenCode at jail start), "can only afford N" from OpenRouter retries with a smaller output limit, and a picked model that needs approval gives way to one that does not. Damaged podman storage gets one line naming p0ssess jail build (and what podman system check --repair deletes). Other raw errors become one plain sentence, with the detail in relay/. An edit run carries the caller's uncommitted changes into its worktree (committed there, so the diff is only the model's), gets one more pass when it changed nothing, has the project's tests run on the result in a container with no network (Go and Node toolchains from the host, read-only; verify_ in config.json skips it), and is applied to the caller's checkout when that is clean and the tests passed (applied and revert; apply_ keeps it to the apply command). The result adds receipt ((model, $cost, saved ~$X), the saving against the same tokens on Claude Sonnet), retries (what p0ssess did, for the p0ssess page; also written to notices.jsonl in the state directory), changed, tests, applied and revert.
Model ids
With no model, the routing engine picks it, as direct does: the use case is use_ if given, else the one the task text looks like (the prompt hook's matcher), else the generic coding or reading work of the mode; stakes default to 2 (3 in edit mode); the best direct or agent option under the budget, caps, rules and approvals wins, from the offline built-in table when the engine is unreachable, and the lead = "none" setting is honored. The result's chosen says which model and why in one line. If nothing fits, the error lists what the engine considered. An explicit model always wins.
run takes an exact OpenRouter id (vendor/, optionally openrouter/ or …#variant), which is accepted as given so the registry snapshot can lag OpenRouter. A bare name is resolved against the registry only when exactly one model matches; otherwise the relay returns the candidates (or "no model matches") instead of guessing (ResolveModelID, internal/).
Tamper detection
Only the relay answers permission requests, interrupts, or otherwise steers a session. The watcher subscribes to permission.replied and the interruption events and records every reply and interrupt the relay itself issues. A permission reply the relay did not issue (a model that found the API password answering its own request, say) or an interruption the relay did not request aborts the session and returns status: tampered with the reason. In normal operation this never fires, because a model's shell commands have no network and webfetch to the loopback API is denied; it is the backstop if those ever fail. The answer is capped at 30,000 characters and the diff at 8,000, so a result stays under Claude Code's 50,000-character limit; past that, Claude Code saves the result to a file and the relay would lose the session id. The full answer and transcript are on disk.
- Progress goes out every 15 seconds while a run is active, which keeps Claude Code's idle timer from aborting the call.
- Limits per run: a cost cap and a maximum runtime (
max_, default one hour). Either interrupts the run. The cap is the run'sruntime_ s max_, which defaults to and cannot exceedcost_ usd max_(default $0.50).run_ cost_ usd - The budget guard. Before each prompt the relay asks the engine to authorize it: rules, the allow and deny lists, stakes (
stakes, else theuse_'s catalog stakes, else 3), privacy,case .p0ssess-private, and the per-task, daily and monthly limits, checked against the run's cap and reserved in the ledger (see ENGINE.md, Enforcement). A refusal returns before the jail is touched; a cap above the per-task limit needs a standing approval. A run that fails before its prompt is sent gives the reservation back; one whose session cost cannot be read is recorded at its cap, marked estimated. A run that ends while nobody waits on it is still recorded. Without the guard (no engine attached) the relay refuses to run. A run's cost comes from the key proxy, which meters every model call (OpenRouter'susage.cost, plusupstream_on bring-your-own-key calls, else a generation lookup) into a file only the proxy container can write, and refuses calls once the run's cap is spent; a call whose cost cannot be read is charged the rest of the cap there, and the relay prices it from its tokens at the route table's price when it can, else records the run at its cap, marked estimated. OpenCode's own session cost, which is $0 for any model missing from OpenCode's price list, is used only when no meter saw the run, and a $0 figure for billed tokens is priced or counted at the cap the same way. The result'sinference_ cost cost_says which (basis openrouter,opencode,tokens,cap). A model with no known price needs an explicitmax_above 0. The command-linecost_ usd p0ssess runuses the same guard. - The command line (
p0ssess run,wait,answer) stays until the run ends or pauses on a permission request, printing progress to stderr, because the watch that enforces the cap and the maximum runtime and records the cost lives in that process.--detachreturnsstill_afterrunning --waitseconds instead. A detached run is unwatched: its cost cap is not enforced and its cost is not recorded until a laterp0ssess wait --session <id>(or the MCPwaittool) picks it up, and its reservation counts as spent at the full cap once its hold (max_+ 15 minutes) passes. Its maximum runtime still holds: the key proxy refuses model calls after it. The MCP server keeps watches alive for as long as it runs.runtime_ s - Cancellation: a cancelled call and a closed stdin both interrupt the OpenCode run. Claude Code does not send a cancellation when its idle timer fires, so the server-side limits matter.
- Attachments are sent as
data:URIs, so the jail never needs the files mounted. Text, PDF, PNG, JPEG, GIF and WebP are accepted, up to 20 MiB each. Audio and video are refused (OpenCode 2.2.5 drops them silently; they belong to the direct path), and so are files that look like secrets. .p0ssess-privatein a repository, or any directory above the working directory, blocks delegation from it.- Transcripts of each run's task and output are kept under
~/; nothing prunes them yet. Inside the jail the session's database is gone with the jail..local/ state/ p0ssess/ relay/ runs/ <session>/
Edit mode
Each edit session gets a detached worktree of HEAD at <repo>/, created before its jail so the jail can mount it. .p0ssess/ is added to .git/. The session's directory is the matching subdirectory of the worktree. When a run ends (or pauses), the relay stages the worktree's changes in the worktree's own index and returns git diff --cached <base>. Nothing is committed or merged. Uncommitted changes in your checkout are not in the worktree. To take a change: git apply <diff_ in your checkout, or review in the worktree; git worktree remove <path> when done. The worktree stays after its jail is removed.
History and files
The relay keeps its state under ~/ ($XDG_ honored; $P0SSESS_ with P0SSESS_ set) and its settings in ~/:
| File | Holds |
|---|---|
~/ |
optional settings: openrouter_, image, selinux (relabel or disable), max_, max_, session_, permission_, blocked_, registry_ |
relay/ |
one line per finished run: time, kind, model, mode, outcome, cost, tokens, duration, session, turn, a 12-character SHA-256 prefix of the task (never its text), and counts of rejected and escalated asks |
relay/ |
what the relay needs to continue a session: repository, directory, mode, model, worktree, jail, whether it has ended |
relay/ |
transcript.md, diff.patch, result.json (the last result), and the full answer when it was truncated |
relay/ |
the jail's record, its password, the proxy's deadline and the egress socket; removed with the jail |
p0ssess 0.3 kept sessions/, runs/, history.jsonl and jails/ in ~/. On its first start 0.4 moves them, under a lock, to relay/, relay/, relay/ and relay/, each only when the new path does not exist yet. When a move fails (the two directories on different filesystems, say) the old path stays and session records are still read from it. That fallback is kept through 0.4.x and removed in 0.5.0. Sessions started by 0.3 ran in shared jails and cannot be continued.
The OpenRouter key is read from openrouter_ (default ~/, or $P0SSESS_). It is passed to the proxy container through its environment and is never printed, logged, written elsewhere or baked into an image.
The relay agent
agents/ is the possession agent: it runs on Haiku, in the background, with omitClaudeMd: true and only the routed MCP tools (direct, run, wait, answer_, abort, models, recommend). Every routed task goes through it; main Claude never calls those tools itself (a PreToolUse hook refuses them outside a subagent, see DESIGN.md, Agents). For the agent path it calls run (and wait while the run is going), then replies with the other model's answer in one <answer> block and a via: <model> · <cost> · <session> line, plus, only when present, files:, diff: <diff_ (never the diff itself; Claude reads the file when the stakes call for it), apply:, session:, permission:, shell internet: on and note:. Results also list the media and office files an edit run added to its worktree (files, regular files inside the worktree only).
The plugin installs it. Background subagents cannot ask for permission, and Claude Code ignores a project's permissions.allow in a folder you have not trusted, so the relay's tools must be allowed at user level: p0ssess setup allow adds those rules (with your consent, through /). Named shortcut agents with a fixed model can be generated as well (see ENGINE.md).
On macOS, and on Linux without podman, the agent path reports itself unavailable; the direct tool and the engine still work.
Tests
go test ./runs the unit tests: the contract test against the pinned OpenAPI document, the recorded event stream, the MCP protocol (progress, cancellation, stdin close), the key proxy and its deadline, the egress proxy's address policy and its CONNECT and plain-HTTP paths, the policy and nftables builders, the session rules, the jail ownership rules, the state migration (including concurrent processes and a failed move) and attachment checks.... P0SSESS_is the end-to-end check against real jails (under a cent in all). It checks:IT=1 P0SSESS_ OPENROUTER_ KEY_ FILE=… [P0SSESS_ IT_ LAN=host:port,…] go test -run Integration -v ./ internal/ relay/ - Egress: a host service through pasta's 169.254.1.2 mapping, 100.100.100.100:53,
[fd7a:115c:a1e0::53]:53and theP0SSESS_targets all fail from inside, while a control container with no filter reaches the host service and the LAN targets;IT_ LAN https://works.openrouter.ai - Identity: your uid, no effective capabilities, an empty
/, no real key in the server's environment.home - A coding task in edit mode completes, the diff has the change, and the main checkout is untouched; a follow-up runs in the same jail; ending the session removes the pod and its record, a later run is refused and
waitreturns the last result. - Hard denies in an allow-all session:
echoruns;sudo,su,ssh,scp,git push,docker,podman,systemctl,sh -c,bash -c,bashandcurl … | share all "Blocked by configuration policy", and so are writes to.env,.ssh/andconfig .git/.config - Read mode rejects an ask and the model reports it could not run the command.
- The jailed shell: no password or key in the environment,
/unreadable, the API, the key proxy and the internet unreachable, an emptyproc/ 1/ environ /, the masks over other sessions' worktrees cannot be unmounted, and the repository is read-only.state - The read tool and webfetch: literal reads of
/andproc/ 1/ environ /and a webfetch to the loopback API are blocked by policy.state - Isolation: two sessions in one repository get two jails; from inside the second, the first's transcript (a marker that is present in the first's own
/), worktree, git admin directory, the relay's state and the first's API are all out of reach, and a worktree symlink to the first's file finds nothing.state - Shell internet: as described above, off and on.
- Startup and crash: five cold starts and removals with and without shell internet (median, minimum and maximum are logged), and a jail whose owning process is killed with SIGKILL is removed by the next sweep.
- Egress: a host service through pasta's 169.254.1.2 mapping, 100.100.100.100:53,
Measured on the development machine (rootless podman 5.8, pasta, image cached): cold start median 0.65 s (0.64–0.66) without shell internet and 0.75 s (0.73–0.77) with it, removal 0.16–0.23 s.
Known limits
- The OpenCode password is in the server's environment, but a model cannot reach it usefully. A shell command the model runs has its environment scrubbed, no network (or only the egress proxy, which refuses loopback), and an unreadable
/(the shell wrapper's user and network namespaces), so it can neither read the password nor call the API. The in-process read tool cannot readproc/ 1/ environ /orproc/ 1/ environ /through a literal path (thestate read:/policy), and a worktree symlink to* /is refused by OpenCode's own binary-file guard (the environment is NUL-separated). OpenCode 2.2.5 still resolves the read permission resource lexically and then follows symlinks, so a worktree symlink can make the read tool open a text file elsewhere in the server container; with one jail per session, the only such files are the session's own database and the read-only repository, so no other session's state is reachable. Even a leaked password is unusable: webfetch to the loopback API is denied by policy and the relay tamper check aborts any reply it did not issue. The OpenRouter key is never in the server at all; it lives only in the proxy container.proc/ 1/ environ - The model can spend through the proxy like it can through OpenCode. The per-run cost cap, the proxy's deadline and the key's own limit on OpenRouter bound this.
data_narrows the providers OpenRouter may use, and some of the cheapest endpoints drop out, so a run can cost more than the model's headline price.collection: deny - SELinux relabeling: with the default
selinux: relabel, podman gives mounted repositories the sharedcontainer_label. Host programs keep working.file_ t restorecon -R <repo>restores the default labels. Set"selinux": "disable"to run the containers withlabel=disableinstead, which leaves your files alone but turns off SELinux separation for the jail. - OpenCode 2.2.5's durable session log (
/) returns only itsapi/ experimental/ session/ {id}/ log log.syncedmarker: its filter drops every session event. The relay uses that marker for the current sequence number, takes live events from/(subscribed before each prompt, because the feed has no replay), and polls the session and its permission requests to catch anything missed across a reconnect.api/ event - Repositories whose
.gitis a file (a worktree or a submodule) can be read but not edited: edit mode needs the.gitdirectory. - An idle session holds memory. Each jail's OpenCode server stays up for
session_after its last run so a follow-up can continue it. Loweridle_ s session_if many sessions pile up.idle_ s