# Air-gapped architecture (/docs/use-cases/government/air-gapped-architecture)



This page covers the air-gapped enforcement `@pleach/core` ships in
v1, where it applies, and what you provide for a fully offline install.

The general story lives at [Air-gapped deployment](/docs/air-gapped-deployment).
This page is the government-procurement detail.

## v1 enforcement substrate [#v1-enforcement-substrate]

The air-gapped option is a two-field mixin on `SessionRuntimeConfig`,
exported as `AirGappedRuntimeOption` from `@pleach/core/runtime/AirGappedRuntimeOption`:

```ts
export interface AirGappedRuntimeOption {
  airGapped: boolean
  airGappedAllowedHosts?: string[]
}
```

The default is `airGapped: false`. Operators opt in by setting both
fields.

### Allowlist semantics [#allowlist-semantics]

`checkAirGappedHost(url, opts)` runs the check. A URL is permitted
when its host matches an allowlist entry exactly or is a subdomain of
one. Matching is case-insensitive, and a leading `.` on an entry is
ignored.

```ts
import { checkAirGappedHost } from "@pleach/core/runtime/AirGappedRuntimeOption"

// No-op in legacy mode.
checkAirGappedHost("https://api.openai.com/v1/...", { airGapped: false })

// Throws AirGappedHostRejectedError — empty allowlist rejects everything.
checkAirGappedHost("https://api.openai.com/v1/...", { airGapped: true })

// Permitted — host matches an allowlist entry.
checkAirGappedHost("https://llm.corp.local/v1/...", {
  airGapped: true,
  airGappedAllowedHosts: ["llm.corp.local"],
})

// Permitted — subdomain match on `.corp.local`.
checkAirGappedHost("https://gateway.corp.local/v1/...", {
  airGapped: true,
  airGappedAllowedHosts: ["corp.local"],
})
```

### Fail-closed by design [#fail-closed-by-design]

With `airGapped: true`, an empty `airGappedAllowedHosts` rejects
**every** URL. Turning on air-gapped mode without naming the proxy,
gateway or mirror you intend to reach is a misconfiguration, and it
surfaces on the first call rather than leaking quietly.

The `governmentAgent` recipe passes `airGappedAllowedHosts` straight
through to `@pleach/core` and adds no validation of its own. The first
outbound URL resolution throws `AirGappedHostRejectedError`, so a
misconfigured deployment fails during smoke test.

### Malformed URLs [#malformed-urls]

A URL that `new URL(...)` rejects throws `AirGappedHostRejectedError`
unconditionally. There's no host to check, so the runtime refuses the
call.

### Error shape [#error-shape]

```ts
export class AirGappedHostRejectedError extends Error {
  public readonly url: string
  public readonly allowedHosts: readonly string[]
  // .cause carries the rejected URL string
}
```

Hosts can catch the error and read the structured fields without
re-parsing the message.

## Where the check runs [#where-the-check-runs]

The check runs in the runtime wherever a provider URL is resolved, so
a host doesn't have to wire it at the edge.

The OpenRouter base URL can be overridden with either of these:

* `PLEACH_OPENROUTER_BASE_URL` (process env)
* `SessionRuntimeConfig.openrouterBaseURL` (per-runtime config)

In air-gapped deployments, point the override at an on-prem proxy that
speaks the OpenRouter protocol, and add that proxy's host to
`airGappedAllowedHosts`.

## What you provide for an offline install [#what-you-provide-for-an-offline-install]

The runtime allowlist covers the call boundary. The install-time
supply chain is yours.

### 1. Dependency vendoring [#1-dependency-vendoring]

Point npm at a **private** registry inside the perimeter, or vendor
a snapshot of `node_modules` and install from that snapshot.

### 2. SBOM [#2-sbom]

The `@pleach/*` release workflow packs a CycloneDX and an SPDX SBOM
(`sbom.cdx.json`, `sbom.spdx.json`) into each package tarball except
the transport packages. No `@pleach/*` package is on npm yet, so none
has been published. The `governmentAgent` recipe accepts
`sbomFormat: "cyclonedx-1.5" | "spdx-2.3"` and stamps it on the
runtime as procurement-visible metadata. Generate the SBOM for your
own deployment in your build.

### 3. Signed artifacts [#3-signed-artifacts]

Releases publish through npm's trusted publisher with npm
provenance. Sign the artifacts you build and deploy (Sigstore, SLSA
provenance) in your own pipeline. See
[Supply-chain risk & SBOM](/docs/use-cases/government/scrm-and-sbom).

## Reference architecture [#reference-architecture]

<Mermaid
  chart="flowchart TB
    subgraph Perimeter
        direction TB
        H[&#x22;Pleach host (Node.js)<br/>airGapped: true<br/>allowedHosts: [proxy]&#x22;]
        L[&#x22;On-prem LLM proxy / gateway<br/>vLLM / TGI / Ollama / Bedrock GCv&#x22;]
        R[&#x22;Private npm registry /<br/>vendored snap&#x22;]
        SIEM[&#x22;Private SIEM<br/>(observe SDK destination)&#x22;]
        H --- L
    end"
/>

Three perimeter boundaries:

1. **Outbound LLM calls.** `checkAirGappedHost()` checks them in the
   runtime, and the allowlist is the only list of permitted hosts.
2. **Install-time dependencies.** Yours today, through a private
   registry or vendored snapshot. A runbook is v1.x scope.
3. **Observability destinations.** `@pleach/observe` ships data
   where the host configures it to. In air-gapped deployments, point it
   at a private SIEM or log aggregator inside the perimeter. See
   [Observability](/docs/observability).

## Verifying enforcement [#verifying-enforcement]

Run a negative test:

```ts
import { governmentAgent } from "@pleach/recipes"
import { AirGappedHostRejectedError } from "@pleach/core/runtime/AirGappedRuntimeOption"

const bot = governmentAgent({
  agencyId: "test",
  airGapped: true,
  airGappedAllowedHosts: ["llm.internal.example.gov"],
  onPremProvider: {
    kind: "ollama",
    endpoint: "https://llm.internal.example.gov",
  },
})

// In a smoke test, point the provider at a public URL and verify
// the runtime rejects it:
try {
  await bot.ask("hello") // routes through a public endpoint
  throw new Error("air-gapped enforcement bypassed")
} catch (err) {
  if (err instanceof AirGappedHostRejectedError) {
    // Expected — the allowlist is doing its job.
  } else {
    throw err
  }
}
```

## Related [#related]

* [Air-gapped deployment (general)](/docs/air-gapped-deployment)
* [Government & public sector landing](/docs/use-cases/government)
* [Supply-chain risk & SBOM](/docs/use-cases/government/scrm-and-sbom)
* [License compatibility](/docs/use-cases/government/license-compatibility)
* [Session runtime](/docs/session-runtime)
* [Gateway](/docs/gateway)
