> For the complete documentation index, see [llms.txt](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/deployment-scenarios/openshell-supervisor-middleware.md). Agents can also search and read this documentation through its [MCP server](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/~gitbook/mcp).

# OpenShell Supervisor Middleware

NVIDIA OpenShell runs AI agents in sandboxes and governs where they may reach: which host, port, method and path, with credentials injected by its supervisor rather than held by the agent. The supervisor can also consult an external decision service, a supervisor middleware, before a sandboxed agent's request leaves and before a response returns to it. In this scenario a <code class="expression">space.vars.X\_Agent\_Name\_Single</code> is that decision service: it inspects what each request carries and each response returns, redacts or refuses by policy, and keeps the evidence record. It never holds the tool credential and never changes the destination; OpenShell keeps those.

The agent runs as a standalone Multi-Protocol agent whose start-up rule set opens a gRPC listener with the Start gRPC Server rule and the OpenShell supervisor middleware binding. Every OpenShell event (request, response preflight, response body, WebSocket session) runs through the agent's rule set as one set of variables: once for a whole body, or once for each event of a streamed reply and each chunk of a large request body. The decision the rules leave is returned to OpenShell. A rule set that leaves no decision is answered fail-closed. See [Multi-Protocol Agents](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/concepts/multi-protocol-agents.md) and [Installing a Stand-alone Multi-Protocol Agent](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/deploy-and-configure/installation-and-configuration/installing-a-stand-alone-multi-protocol-agent.md).

The middleware uses OpenShell's HTTP hooks and needs OpenShell 0.1.9 or later. An earlier OpenShell gateway does not offer the hooks: the agent refuses it when it asks the middleware to describe itself, so the gateway does not start with the middleware registered, and the agent's log says why, at most once a minute.

```mermaid
%%{init: {"theme": "base", "themeVariables": {"fontFamily": "Roboto, sans-serif", "primaryColor": "#e6f2c7", "primaryTextColor": "#000000", "primaryBorderColor": "#89a842", "lineColor": "#999999", "edgeLabelBackground": "#e8e8e8"}, "flowchart": {"padding": 22}}}%%
flowchart LR
    A["AI agent
    in an OpenShell sandbox"]
    S["OpenShell supervisor
    checks reach, injects credentials"]
    M["Multi-Protocol agent
    (supervisor middleware)
    inspect, redact, deny, record"]
    T["&nbsp;Tools, MCP servers, APIs&nbsp;"]
    G["HTTP gateway agent
    (model gateway)"]
    L["&nbsp;Models&nbsp;"]
    A --> S
    S -.->|"gRPC: evaluate request,
    evaluate response"| M
    S -->|"admitted request"| T
    S -->|"admitted request, stamped with the
    request id, sandbox id and calling process"| G
    G --> L
```

## What the middleware does

* Request path: the rules see the request's host, method, path, headers and body. Guardrail Pack scans (identifier lists, patterns with card-number validation) run on the body; the rules return Allow with an edited body, or Deny with a reason code that OpenShell returns to the sandbox as a 403. A text request body larger than the payload limit (JSON, text, XML, a form) is read chunk by chunk, so a large upload is scanned rather than refused; a body that can be read neither whole nor in chunks (a compressed body, or a large body that is not text) is denied with reason code `request_body_encoded` or `request_body_over_limit`, so nothing leaves unread.
* Response path: at preflight the rules choose whether to inspect the response; on a whole body they return Pass, Transform (an edited body) or Block.
* Streamed replies: a streamed model reply (server-sent events in the OpenAI chat completions format) is read inline, event by event, with the cross-event checks of the [AI API Gateway](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/concepts/ai-api-gateway.md). A card number or identifier split across events is still caught: the text is held back until it is cleared, then delivered redacted. The text held back is as long as the longest thing the checks look for: the longest term in the identifier list plus the widest card number the card pattern can match (37 characters for the pattern shipped in the rule set, a number of 13 to 19 digits with separators). Delivery trails the model by that many characters, a fixed lag that does not grow along the stream. In a test with a 25-character longest term, the text arrived 62 characters behind the model: about 200 ms at 300 characters a second. A longer term in the identifier list lengthens the lag of every streamed reply. The first event of a reply arrived 7 to 11 ms later than without the middleware. A character split across events (an emoji, an accented letter) is delivered whole, and one evidence record is kept for the whole stream. A block after the reply has started cuts the delivery.
* Header changes: the rules can queue header writes and removals for OpenShell to apply, for visible end-to-end headers only. The identity stamp below uses this.
* Findings: counts only, never the matched values, returned to OpenShell so its own audit event shows a non-zero finding count.
* Evidence: one capture record per decision, carrying OpenShell's request id as the exchange id and its sandbox id, so the record and OpenShell's audit event share keys. The record also names the process inside the sandbox that made the call, as OpenShell reports it: its executable and the executables that started it, nearest parent first (`originatingProcess`). See [AI Audit Evidence](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/concepts/ai-audit-evidence.md).

## Attaching the middleware

The same registered middleware is attached in the OpenShell policy once for each group of hosts, and the `mode` in the attachment's `config` sets what it does there:

* `mode: inline` on tool, MCP and API hosts, and on model hosts the middleware is to read itself: the scans and decisions above. The evidence record names the destination host and the call: for an MCP request the method and tool name (`tools/call lookup_customer`), otherwise the HTTP method and path.
* `mode: stamp` on the model gateway host: no scans, and responses are skipped, so model traffic flows through the [AI API Gateway](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/concepts/ai-api-gateway.md) untouched by the middleware. The request gains the identity stamp below, so the model gateway's own evidence rows carry OpenShell's keys and the admission is recorded without content.
* `stamp: true` added to an inline attachment: the host is read inline and the request is stamped too, so where the model gateway sits behind the middleware both check the content and their records still join.

```yaml
network_middlewares:
  dm-model:
    middleware: tomorrowx-data-mediation
    config:
      mode: inline
      stamp: true
    on_error: fail_closed
    endpoints:
      include:
        - gateway.example.internal
```

The identity stamp is four request headers. The AI API Gateway's Guardrail Session rule reads them into the gateway's record:

| Header                    | Carries                                                                                    |
| ------------------------- | ------------------------------------------------------------------------------------------ |
| `X-CAP-Exchange`          | OpenShell's request id: the exchange id of both records of the call                        |
| `X-CAP-Sandbox`           | OpenShell's sandbox id                                                                     |
| `X-CAP-Process`           | The executable of the process in the sandbox that made the call, when OpenShell reports it |
| `X-CAP-Process-Ancestors` | The executables that started it, nearest parent first, comma separated                     |

### The middleware alone, or with the AI API Gateway

The middleware alone checks and records what an agent in a sandbox sends and receives at the OpenShell boundary, model replies included. In its slot it can allow, edit or refuse a call, never redirect one, so these stay with the AI API Gateway: routing a call to a chosen provider or region, refusing prohibited providers, cost and budget metering, tokens replaced in the request and restored in the reply, model formats other than OpenAI chat completions, and applications that do not run in OpenShell. Where both are deployed, choose for each model host whether the gateway checks the content (`mode: stamp`) or both do (`mode: inline` with `stamp: true`); in either case one exchange id joins the records.

## Registration and policy

OpenShell registers the middleware in its gateway configuration by name and gRPC endpoint. For anything beyond a laptop the endpoint is TLS with a certificate the gateway trusts, and the gateway signs every call with a bearer token the agent verifies against the gateway's public key, audience and gateway id, which the Start gRPC Server rule reads from the SupervisorMiddleware credential vault entry. The attachment in the policy is set to fail closed: if the agent is unreachable the call is refused, and the gateway will not start while the middleware cannot be described. Leave the agent running before sandboxes are created, and give the registration a timeout above OpenShell's 500 ms default, so that an agent's first call after a reload, on a busy node, is not refused. 2 s is the tested value. The first call after a reload or a pod restart was answered within 75 ms, but at node saturation about 1% of calls took longer than 500 ms.

The rules behind the decisions are ordinary rule sets. Which checks run, what a match does and the capture mode are live settings changed in the Console without a redeploy, and the checks carry the same setting names as on the AI API Gateway:

| Setting             | What it does                                                                                                                                                                                               |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GUARD_LIST_CHECK`  | On scans requests and responses against the armed identifier list. Off skips the check                                                                                                                     |
| `GUARD_LIST_ACTION` | What an identifier match does. Redact replaces it with `[PROTECTED]`; Observe counts and records it and changes nothing; Block refuses the request or blocks the response with reason code `content_match` |
| `GUARD_CARD_LUHN`   | On catches card numbers that pass the Luhn checksum, in requests and responses. Off skips the check                                                                                                        |
| `GUARD_CARD_ACTION` | What a card match does. Redact replaces it with `[CARD]`; Observe and Block as above                                                                                                                       |

Observe returns the finding count to OpenShell while the call leaves untouched, so the same deployment can run first as an observer of what agents send and then be switched to mediation with one setting.

## Running the middleware as a Kubernetes fleet

OpenShell itself runs in a Kubernetes cluster, and so does the middleware in anything beyond a laptop: a fleet of identical Multi-Protocol agent pods behind one Service, managed by a cluster slave console inside the cluster on behalf of the master console wherever the operators work. The shape reuses the cluster model of <code class="expression">space.vars.X\_Product\_Name</code> (see [Managing Large Clusters](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/deploy-and-configure/administration-functions/managing-large-clusters.md) and [Creating a Cluster Slave Console Instance](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/deploy-and-configure/installation-and-configuration/creating-a-cluster-slave-console-instance.md)); nothing in it is specific to OpenShell except the port the gateway registers.

```mermaid
%%{init: {"theme": "base", "themeVariables": {"fontFamily": "Roboto, sans-serif", "fontSize": "12px", "primaryColor": "#e6f2c7", "primaryTextColor": "#000000", "primaryBorderColor": "#89a842", "lineColor": "#999999", "edgeLabelBackground": "#e8e8e8"}, "flowchart": {"padding": 16, "nodeSpacing": 24, "rankSpacing": 32}}}%%
flowchart TB
    MC["&nbsp;CAP master console&nbsp;
&nbsp;run by the customer or partner,&nbsp;
&nbsp;outside the cluster&nbsp;"]
    subgraph K["&nbsp;Customer Kubernetes cluster: the checks run inside this boundary&nbsp;"]
        subgraph OS["&nbsp;NVIDIA OpenShell&nbsp;"]
            GW["&nbsp;OpenShell gateway&nbsp;
&nbsp;policy, middleware registration&nbsp;"]
            SBX["&nbsp;Sandbox pods&nbsp;
&nbsp;AI agent + OpenShell supervisor&nbsp;"]
        end
        SC["&nbsp;CAP cluster&nbsp;
&nbsp;slave console&nbsp;"]
        SV["&nbsp;Service sm:50051&nbsp;"]
        subgraph F["&nbsp;CAP supervisor middleware&nbsp;"]
            direction TB
            P0["&nbsp;sm-0&nbsp;
&nbsp;Multi-Protocol PDA&nbsp;"]
            P1["&nbsp;sm-1&nbsp;
&nbsp;Multi-Protocol PDA&nbsp;"]
            PN["&nbsp;sm-N-1&nbsp;
&nbsp;Multi-Protocol PDA&nbsp;"]
        end
    end
    MC <-.->|"feed, heartbeats, counts;
dials, evidence, logs"| SC
    SC -->|"deploy, roll
one pod at a time"| F
    MC ~~~ GW
    GW -->|"creates sandboxes,
attaches policy"| SBX
    SBX -.->|"OpenShell supervisor
middleware API (gRPC):
evaluate request, response"| SV
    SV --> F
    style MC fill:#d7e9a4,stroke:#89a842,stroke-width:3px
    style SC fill:#d7e9a4,stroke:#89a842,stroke-width:3px
    style P0 fill:#d7e9a4,stroke:#89a842,stroke-width:3px
    style P1 fill:#d7e9a4,stroke:#89a842,stroke-width:3px
    style PN fill:#d7e9a4,stroke:#89a842,stroke-width:3px
```

Read the diagram as two paths that meet at the supervisor middleware pods. On the right is OpenShell: its gateway creates the sandboxes and attaches their policy, and the supervisor in each sandbox calls the middleware through the Service for every request and response the policy sends to it. On the left is management: the master console reaches the pods through the cluster slave console. The darker boxes are the <code class="expression">space.vars.X\_Product\_Name</code> pieces: the master console, the cluster slave console and the pods of the supervisor middleware, each a Multi-Protocol <code class="expression">space.vars.X\_Agent\_Name\_Single</code> (<code class="expression">space.vars.X\_Agent\_Short\_Single</code>). The Service is Kubernetes; the gateway and the sandboxes are OpenShell.

The middleware plugs into OpenShell's own supervisor middleware slot and is deployed and owned by the customer beside OpenShell, not inside it. Every check runs inside the customer's cluster: the rules run in the pods and keep their evidence in each pod's own store, and they call nothing outside the cluster unless the customer chooses to, for example to consult a classifier model. The master console is run by the customer or a partner, never as a TomorrowX service; it receives heartbeats and counts, and evidence rows reach it only when an operator reads them through the cluster slave console.

How the pieces behave:

* **One engine per pod, N pods as a StatefulSet.** The pods have stable names, so the slave console defines them once, up to the maximum replica count, from a declared list given in its environment; a scale-up or a replaced pod needs no change on the master. Each pod keeps its engine on its own volume and comes back serving after a restart without the slave's help. A setting made on a pod from the master is kept on that pod's volume, so a pod added by a scale-up starts on the defaults in the feed configuration. Put the settings every pod needs, such as the evidence bucket and the shipping switch, in the feed configuration, or set them on each new pod after its first deploy.
* **The slave console is not in the traffic path.** It is born headless from a ConfigMap (master URL, node name, declared agents) and a Secret (the node password), fills its SupervisorMiddleware credential vault entry at start from a second mounted Secret (from console build 30200), attaches to the master, pulls only the extensions the feed resolves to, deploys to a pod once it has come online and finished starting (from console build 30215), and rolls a feed change across the pods one at a time, waiting for each pod's gRPC health port (50052) to answer SERVING before the next. An extension update installed on the master is held on the slave and shown on the master's cluster page until the feed is next rolled or **Deploy to agents** is used (from console build 30200), so installing an extension does not by itself change what the fleet runs. If the slave pod dies the fleet keeps serving as last deployed. A rule that reads a credential vault entry when its rule set loads (a messaging rule that reads its webhook address, for example) needs that value in the slave console's vault. From console build 30210 the slave checks a configuration against its own vault and extensions before it deploys, on a roll and for a pod that comes online: a configuration with a rule that cannot load is refused, nothing is sent, the pods keep serving what they have, and the master's cluster page shows the rule's message on the Cluster Error line. Enter the value on the slave console's vault page and use **Deploy to agents**. From agent build 30210, a pod whose rule set still fails to load closes its listener and its health port, so it leaves the Service and a roll stops at it.
* **The gateway holds one address.** It registers the middleware against the Service in front of the fleet, over TLS with a certificate that carries the Service name, and signs every call with its own key; the pods verify the token. Before a pod reloads it drains: its health port reports not ready while the pod keeps serving, the readiness probe takes it out of the Service, and the pod then asks the gateway to reconnect, which lands on a pod that is ready. From agent build 30210 a pod that is terminated (a scale-down, a node drain, a deleted pod) stops the same way: it drains, then seals the evidence segment it has open and ships it before it exits. Allow for the drain period plus the upload in the pod's termination grace period. A forced kill does neither, and a pod stopped while it holds a backlog of unshipped segments ships them once it is back and handling calls, so keep the pods' volumes persistent.
* **The master sees the whole estate.** The node's agents appear in the master's API and the AI Control Plane as `node/agent` names; dials, evidence and logs are read and written through the node, and a dial can be applied to every pod of the fleet in one action. Evidence rows are read from each pod's own store over its management port, never from disk.
* **A Console version is an image tag.** The slave image carries the Console build and installs it into the persistent volume on start; the agent image is the standalone Multi-Protocol agent with no Console in it.

What a rolling change costs the caller: the one call in flight on each connection at the instant a pod closes its listener. The Start gRPC Server rule in the SM Startup rule set sets five seconds to report not ready before closing. That is longer than a readiness probe of two seconds with a failure threshold of one, plus the time the Service takes to notice. Calls already on the draining pod finish there, and new calls go to the other pods. At least N-1 pods serve at every moment of the change. At 64 concurrent callers across four pods (32 sandboxes), a roll of all four pods refused 45 of 694,130 calls and a pod deleted under the same load refused 7 of 710,138: about one call for each sandbox attached to the closing pod. Some were refused before the request left the sandbox; the others had completed upstream and the response could not be delivered. Without the drain setting, the gateway's open connection breaks when a pod reloads, and with the policy set to fail closed, the requests in the two seconds it takes to reconnect are refused.

### Shipping the evidence off the pods

Each pod writes its evidence to its own volume in hash-chained segments. That volume is a buffer for an outage of the archive, not the archive itself: with shipping on, sealed segments and their chain manifests are uploaded to an S3-compatible evidence bucket and the local store is kept under a size cap.

The settings are live on the agents and carry the same names as on the AI API Gateway:

| Setting                                              | What it does                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `CAPTURE_SHIP`                                       | On uploads sealed segments. Default Off                                                                                                                                                                                                                                                                                                                                                                                        |
| `CAPTURE_BUCKET_URL`                                 | Base URL of the evidence bucket. A path after the bucket keeps this fleet's evidence under its own prefix. Blank keeps shipping off even when the switch is On                                                                                                                                                                                                                                                                 |
| `CAPTURE_SHIP_PROFILE`                               | The AWS credentials profile that signs the uploads. Leave blank on a fleet that signs with its platform role (Guardrail Pack 2026-11 update 3 or later)                                                                                                                                                                                                                                                                        |
| `CAPTURE_FORWARD`, `CAPTURE_FORWARD_URL`             | Also forward records to a SIEM receiver. While forwarding is on, a segment stays on the pod until it has been forwarded; when it is switched off, that hold lapses after two minutes (update 5 or later)                                                                                                                                                                                                                       |
| `CAPTURE_RETAIN_DAYS`                                | Days to keep a shipped segment on the pod. A segment is removed whole: its body, its manifest and its shipped marker (update 5 or later)                                                                                                                                                                                                                                                                                       |
| `CAPTURE_STORE_CAP_MB`                               | Size cap of the local store, measured as the disk space it occupies. Over the cap, shipped segments are removed oldest first, down to nine tenths of the cap (update 5 or later); with nothing shipped left to remove, new capture stops rather than fill the volume or delete a sole copy. Keep the cap below the size of the pod's volume: on a full volume nothing can be written or marked as shipped until space is freed |
| `CAPTURE_SEGMENT_RECORDS`, `CAPTURE_SEGMENT_MINUTES` | Records to a segment, and minutes a part-filled segment may stay open, before it is sealed and shipped. Small segments reach the bucket sooner; large ones mean fewer files and uploads under load (update 4 or later)                                                                                                                                                                                                         |
| `CAPTURE_STRICT`                                     | On refuses a call whose decision cannot be recorded. Default Off (update 4 or later)                                                                                                                                                                                                                                                                                                                                           |

On Amazon EKS the pods need no AWS keys. Give the pods a service account of their own, associate it with an IAM role through EKS Pod Identity, and grant that role `s3:PutObject` on the bucket, or on the fleet's prefix in it, and nothing else. With the AWSCredentials vault entry left blank on the slave console and `CAPTURE_SHIP_PROFILE` blank, each pod signs its uploads with that role (Base Rules build 30200 or later). Recreate the pods after the association is made: a pod created before it has no credentials. Set `AWS_EC2_METADATA_DISABLED=true` on the pods, so that a pod without an association fails instead of signing as its node.

Each pod writes under `capture/<pod name>/<date>/` below the bucket URL. Shipping runs when a decision is captured, and the first pass after it is switched on ships every sealed segment the pod already holds. A pod that is handling no calls does not ship: a part-filled segment that has passed its minutes limit is sealed and shipped by the next call.

Where pods can sit without calls while they still hold evidence, add a timer rule set: a rule set whose only rule calls the rule set that holds the evidence store chain, set under Timers in the configuration the pods run, at an interval of 60 seconds. The chain then also runs at that interval with no call arriving: sealed segments ship within a minute, and a part-filled segment is sealed and shipped once it has passed its minutes limit. A timer run records nothing and raises no notice.

**When the archive cannot be reached.** The pod goes on writing to its volume until the store reaches the cap, then stops recording. Calls are still served and nothing unshipped is deleted. When the archive returns the backlog ships, shipped segments are removed and recording resumes. Decisions made while the store was stopped have no evidence record. While the archive takes segments more slowly than the pod writes them, the store fills again each time room is freed, and the pod records what it has room for until the archive has caught up. In a test with shipping switched off and a 64 MB cap, four pods under sustained load stopped at the cap holding about 1,170 unshipped segments, kept serving, and shipped every one after shipping was switched back on.

**Strict capture.** With `CAPTURE_STRICT` On, a call whose decision cannot be recorded is refused instead: a request is denied before it leaves the sandbox and a response is withheld, with the reason code `evidence_unavailable`. The store is checked before the record is taken: while it is stopped at its cap or its segment writes are failing, the call is refused first, so any record of it shows the refusal. A full store cannot record its own refusal, so the record of it is OpenShell's own audit event. Only the pod that cannot record refuses; a pod with room goes on serving. A withheld response means the call itself has already run.

**Alerting the operator.** A stop and its recovery are each raised once for an episode. The stop is raised with the first decision that cannot be recorded, and a warning is written to the pod's log. The recovery is raised once recording has stayed on for one minute and the segments still waiting for the archive take no more than half of the cap, so a store that fills again while a backlog ships raises nothing in between. A fault that lasts, such as an archive that cannot be reached, is written to the pod's log when it starts, once a minute while it lasts and once when it ends. Guardrail Alert turns each notice into an alert line, `CAP evidence store STOPPED on <pod>` or `CAP evidence store RESUMED on <pod>`, in the same form as its alert for an escalated decision. How the alert is delivered is your choice: chain the messaging rule you use behind Guardrail Alert (a webhook post, email or SMS), or none, in which case the warning in the pod's log is the only sign. An alert carries outcome, reason codes, counts and identifiers, never matched values or content.

### Sharing load across the pods

Each sandbox's supervisor holds one connection, and the Service places connections, not calls: all of a sandbox's calls go to the pod its connection landed on, and a pod added later takes only sandboxes created after it. The Service places each connection on a pod at random, so the spread evens out only with many sandboxes for each pod. In tests with 32 sandboxes over four pods, one pod held a single connection while another held 12. With many sandboxes of modest call rate, load spreads evenly by itself. Where it does not, there are two ways to share it.

**Reconnect the sandboxes at an interval.** Set **Rebalance clients every (minutes)** on the Start gRPC Server rule. Each sandbox then reconnects at that interval and is placed again over the pods running now, so a pod added by a scale-up is taking load within one interval. Five minutes is a reasonable value. In the tested OpenShell release a reconnect fails the calls the sandbox has in flight at that moment: about one for a sandbox with two concurrent clients, most or all of them for a sandbox with dozens. The setting places connections, so a few very busy sandboxes can still leave one pod busier than the others.

**Balance each call.** Put a load balancer that routes each gRPC call, such as Envoy, between the Service the gateway registers and the pods, sending each call to the pod with the fewest calls in flight. Every pod then takes an even share of every sandbox, a pod added by a scale-up takes calls as soon as it is ready, and the pods' requests to reconnect reach the balancer, not the sandboxes, so they cost no calls. The balancer needs:

* Its own TLS certificate from the CA the gateway trusts, carrying the Service name the gateway registers, so the registration does not change; TLS again to each pod, checking the pod's certificate; and the gateway's token passed through untouched, since the pods verify it.
* A higher limit on stream resets from a client. The OpenShell supervisor resets many of its streams once the response is complete, and the default HTTP/2 guard against rapid resets closes a busy sandbox's connection within seconds, failing every call in flight on it. In Envoy, set `stream_reset_burst` and `stream_reset_rate` in the HTTP/2 options of the listener the sandboxes connect to, for example to 20000 and 10000 (the defaults are 1000 and 33 a second). Admit only the OpenShell namespace to that listener.
* Health checks on each pod's gRPC health port (50052), so a draining pod stops receiving calls before it closes. Tolerate one late answer from a busy pod (a timeout of about 2 seconds and two failures to take it out): a check that takes a pod out on one slow answer takes saturated pods out under load and pushes their calls onto the rest.
* Retries only for calls no pod has seen (a refused stream, a failed connect), so a call is never mediated or recorded twice.

The balancer's own replicas are placed by connection, as the pods are on the Service, so size each replica for the busiest share rather than the average. A balancer adds about 1 ms to a sandbox request at light load and takes about one core for each 1,500 mediated calls a second.

One thing per-call balancing gives up: the request and response calls of one OpenShell request usually reach different pods. A response's evidence record on another pod still carries the conversation the request named, which it reads from the request's own headers, but no MCP method or tool. Each pod logs, at most once a minute, how many MCP requests it released without seeing their response; behind a per-call balancer that count runs in step with the MCP call rate. Where response records must carry the MCP call, share load by reconnecting instead.

### Sizing the fleet

Measured figures are on [Performance Benchmarks](https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/operate-and-observe/performance-data/performance-benchmarks.md). In outline:

* A pod of 2 vCPU handles about 950 mediated calls per second at capture mode Full. Run enough pods that the fleet carries its load with one pod gone. A pod deleted under load refused about one call for each sandbox attached to it, and its replacement was serving 13 seconds after the deletion. A pod that is killed does not drain: the sandboxes attached to it had their calls refused for 28 seconds, until their supervisors reconnected.
* A streamed reply read inline runs the rule set once for each of its events, and a large request body once for each chunk, so size a fleet that reads model traffic by events and chunks a second, not by requests. The figures above are for whole-body calls. In a test, each event read this way cost about 0.17 ms of pod CPU, against about 2 ms for a whole-body call. Events that reach the supervisor together are read as one chunk, so the cost follows the chunks delivered rather than the events the model sent.
* On the Service alone, load is shared by sandbox, not by call: see [Sharing load across the pods](#sharing-load-across-the-pods) for two ways to share it.
* Capture mode Full stored about 4.4 KB of evidence per mediated 1 KB call, as two records. On a busy fleet set `CAPTURE_SEGMENT_RECORDS` to several hundred or 1,000: at 25 records a pod at full load seals several segments a second. Size each pod's volume as an outage buffer: peak decisions per second, times bytes per decision, times the longest archive outage to survive. Set `CAPTURE_STORE_CAP_MB` at about 70 to 80 percent of the volume, or use a lighter capture mode where the full bodies are not needed.
* OpenShell's own inspection of MCP traffic refused request bodies over 64 KiB in the tested release, with or without the middleware attached.
* Clients inside a sandbox should honour DNS time-to-live. OpenShell's policy DNS hands out an address whose mapping can lapse, and a client that caches the address longer is refused.

Use cases for this scenario include:

* Sensitive data kept out of tool calls and MCP requests made by autonomous agents
* One evidence trail across an agent's tool calls and model calls
* Regulated environments where the agent runtime and the content controls must be separate enforcement points


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tomorrowx.com/cap/vZHo2144m1e79o3WX0RU/deployment-scenarios/openshell-supervisor-middleware.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
