Skip to content

Extensions

Last updated: 2026-11-22T07:10:00-03:00 (UTC-3)

Extensions let an operator add small pieces of logic to the gateway - today a custom guardrail - without changing the gateway itself and without giving that logic access to the host. A plugin is a WebAssembly module, or JavaScript source, plus a signed manifest. The gateway runs it in process, in a sandbox, a fresh instance for every call.

Flag Default What it turns on
extensions false The runtime, the admin API under /api/v1/admin/extensions, the execution audit and the console page Settings → Extensions
extension_guardrails false Guardrail provider type extension (requires extensions and guardrails)
extension_submissions false Team administrators submit plugin versions for review (requires extensions)
extension_javascript false The JavaScript runtime (QuickJS on the same sandbox), used by MCP code mode and, with extension_guardrails, by JavaScript plugins (requires extensions)

All are operator controls under plan entitlements. With them off nothing is loaded, compiled or run.

A plugin runs on wazero (pure Go, no CGO), with WASI preview 1 and nothing behind it:

  • no file system, environment variables, arguments or standard input; output streams are discarded;
  • a fake clock and deterministic randomness;
  • no sockets.

What a plugin can do is limited to the aigw host functions (ABI aigw-ext-v1):

Function What it does
input_len() -> i32, input_read(ptr, len) -> i32 Read this call’s input (for a guardrail, a JSON document)
output_write(ptr, len) -> i32 Append to the answer; past the limit the call ends with output_limit and nothing is returned
result_read(ptr, len) -> i32 Read the last host result (the http_call answer)
http_call(ptr, len) -> i32 Only when the manifest grants it: send one HTTP request through the gateway

A module that imports anything else - an ungranted host function, another import module, an imported memory - is refused when it loads. Tables live outside the memory ceiling, so a table may have at most 65,536 entries and plugins run without the WebAssembly reference-types feature: table.grow and multiple tables do not compile. Go, TinyGo and AssemblyScript output needs nothing more; for Rust, build with -C target-feature=-reference-types.

Every call has a deadline (the call is interrupted, even inside an infinite loop), a memory ceiling in 64 KiB pages, an output limit and an HTTP call budget. Calls are admitted per replica and per team; past either bound a call is refused at once and counted, never queued. A trap, a panic or a non-zero exit inside the plugin is an outcome of that call; the gateway keeps running. Activating another version stops new calls on the old one at once and releases it when the calls already running finish.

Network only through the host. http_call takes {"method", "url", "headers", "body"}. The URL’s origin must be in the plugin’s signed manifest and in the calling team’s binding. A header may reference a secret by name - {"name": "Authorization", "value": "Bearer ", "secret": "API_TOKEN"} - and the gateway appends the calling team’s value inside the host; the plugin never sees it, and an answer that echoes the secret back is refused. Requests go through the same pinned, redirect-free egress client as every other integration (private ranges, loopback and cloud metadata refused unless allowed in extensions.http). The answer is {"status", "content_type", "body"}, bounded by extensions.http.max_response_bytes.

What the sandbox does not cover. Calls share the process and CPU caches, so timing side channels between tenants are not prevented; tenants that need physical isolation need separate replicas. A plugin can spend its whole budget. A signature proves who approved a plugin, not that its logic is right. See the threat model.

{
"id": "ticket-guard",
"version": "1.0.0",
"name": "Ticket guard",
"description": "Denies a code name, redacts ticket references",
"kind": "guardrail",
"abi": "aigw-ext-v1",
"host_functions": ["http_call"],
"egress": ["https://classifier.internal.example"],
"secrets": ["API_TOKEN"],
"limits": {"memory_pages": 512, "timeout_ms": 200, "max_output_bytes": 65536, "max_http_calls": 1}
}

Lists are sorted and unique, so a manifest has one canonical encoding. Limits are capped by the boot ceilings in the extensions block. The signature is Ed25519 over ai-gateway extension signature v1\n followed by the hex SHA-256 of {"manifest": <canonical manifest>, "module_sha256": <hex>}, made offline with extsign:

Terminal window
go run ./cmd/extsign keygen -private-key release.key # once; prints the public key
go run ./cmd/extsign sign -private-key release.key -key-id release \
-manifest manifest.json -module plugin.wasm # prints {"key_id", "value"}

The operator lists the public keys it trusts in extensions.trusted_keys (boot configuration only; no API adds one). The gateway checks the signature every time it loads a version, never trusting what is stored: a tampered module or manifest, or a key removed from the list, makes the version refuse to load, and the hook fails according to its on_error.

With extension_javascript and extension_guardrails on, a guardrail plugin can be JavaScript source instead of a WebAssembly module. It runs on the same pinned QuickJS engine as MCP code mode, inside the same sandbox, with the same signature, lifecycle, team bindings, limits, admission and audit as a WebAssembly plugin. There is no compile step: you sign the .js file itself.

The manifest says so with "runtime": "javascript" (a manifest without runtime is WebAssembly; "runtime": "wasm" is refused, so a manifest keeps one canonical encoding). The runtime is signed with the rest of the manifest, so a signature never moves a payload to the other runtime. extensions/examples/javascript-guardrail has a complete example: plugin.js (deny a code name, redact TCK-123… tickets, like the Go example) and its manifest.json.

function guardrail(request) {
// request: {hook, stage, texts, model, team_id} - the same input a
// WebAssembly plugin reads with input_read.
if (request.texts.some((t) => t.includes("forbidden"))) {
return { action: "deny", reason: "forbidden_word" };
}
return { action: "allow" };
}
  • Entry point. The source must define function guardrail(request) (a function declaration or a top-level const guardrail = ...) that returns the verdict object synchronously: {"action": "allow"}, {"action": "deny", "reason": "label"} or {"action": "redact", "texts": [...], "reason": "label"}. The gateway serializes it with JSON.stringify and validates it as strictly as a WebAssembly verdict: unknown fields, another action, a reason outside [A-Za-z0-9_./-]{1,64} or a redact without exactly one text per input text are a malformed verdict, which follows on_error. A missing guardrail, a promise (an async function), a non-object or an exception is the outcome program_error, which also follows on_error.
  • What the script sees. Each call is a fresh QuickJS instance: top-level code runs again on every call and nothing - globals, prototypes, closures - survives into the next call or reaches another team. The source runs in strict mode as the body of a function (opened on its first line, so error positions match the file), after a prelude that removes the QuickJS std and os objects; reached again through import("qjs:std") they find no file system, environment or process, because the sandbox has none. Top-level declarations are local to the call, so a plugin may shadow any name, host included, without breaking the call. The only host object is the frozen global host. There is no fetch, require, timers or real clock.
  • Network. host.http_call(request) exists only when the manifest grants http_call. It takes the same {"method", "url", "headers", "body"} as the WebAssembly host function, goes through the same checks (signed egress and team binding, secrets by reference, budget, response bound, secret echo refusal) and returns {"status", "content_type", "body"}. A refusal throws an Error whose code is not_granted, denied, budget, invalid_request, upstream or too_large; the script may catch it. Without the grant the gateway refuses the operation itself, not just the missing function.
  • Limits. limits.memory_pages is the instance’s whole memory and must be at least 32 (2 MiB); the script heap is that memory minus 1 MiB kept for the engine. An exhausted heap (even by many small objects, when QuickJS can only throw null; a script that throws null itself is treated the same way) or runaway recursion ends with memory_limit, a loop with timeout, a verdict longer than max_output_bytes with output_limit. These are outcomes the client can force, so the guardrail fails closed whatever on_error says, as for WebAssembly.
  • Upload. The JSON body carries the text in source instead of module_base64: {"manifest": {...}, "source": "function guardrail(request) {...}", "signature": {...}}. The signed digest is the SHA-256 of the UTF-8 bytes of source, so sign exactly the file you send (extsign sign ... -module plugin.js). The source must be UTF-8 without NUL bytes and at most extensions.max_module_bytes; the request body is bounded at 4/3 of that plus 64 KiB (past it, 413 module_too_large), which leaves room for ordinary JSON escaping. The console reads the file as strict UTF-8, keeping a byte-order mark, so the bytes it sends are the bytes you signed. On upload and on approval the source is compiled - never run - and a syntax error is refused as invalid_source. Team submissions use the same source field.
  • Runtime off. With extension_javascript off, JavaScript versions cannot be uploaded, submitted or approved (404 feature_disabled), and an active JavaScript version does not run: the execution is recorded as runtime_disabled and the guardrail follows on_error.
  • Upload (global administrator): POST /api/v1/admin/extensions with the manifest, the module in base64 and the signature. The module is compiled and its imports checked before anything is stored. activate: true makes it the active version.
  • Submit (team administrator, extension_submissions): POST /api/v1/admin/extensions/submissions with an unsigned version for a team it administers. It is stored pending_review and runs nowhere.
  • Review (global administrator): approve with a signature by a trusted key over exactly the submitted manifest and module - approval cannot widen egress, secrets, host functions or limits - or reject.
  • Activate, upgrade, roll back: POST .../{id}/activate {"version"} points the plugin at an approved version ("" deactivates it); POST .../{id}/rollback returns to the previous one. Every execution reads the active version live, so this applies on every replica without a restart.
  • Inventory: GET /api/v1/admin/extensions lists every version with its manifest, module digest and size, status, signature verdict (checked now against the trusted keys) and whether this replica has it loaded. Building it never runs plugin code. It also carries the extensions object: every ceiling of the YAML block under its own name (max_module_bytes … audit_retention_days, http.*, code_mode.*), effective and read-only (it was named limits and held five of them). trusted_keys is served as fingerprints and http.allow_loopback_http and http.allowed_private_cidrs not at all: they widen what a plugin may reach, which stays boot trust.

A plugin installed by the global administrator can serve every team. A plugin a team submitted belongs to that team and runs only for its requests; for any other team it does not apply.

A team picks a plugin with a binding (PUT .../{id}/bindings/{team}, team administrators for the teams they administer): enabled and egress, which must be origins from the active version’s signed manifest - a binding only narrows. Secrets are set per team (PUT .../bindings/{team}/secrets/{name}), only for names the manifest lists, write-only and encrypted with the provider keyring (AES-256-GCM bound to plugin, team and name). Without an enabled binding a plugin runs with no network at all. Removing a binding cuts its egress and secrets on the next call.

With extension_guardrails on, a guardrail can delegate to a plugin:

guardrails:
- id: tickets
name: Ticket references
mode: block # or monitor: record the verdict, never enforce it
stages: [input, output]
provider:
type: extension
extension: ticket-guard
on_error: block # block (default) or allow

The plugin gets the texts the guardrail would send an external service, after the gateway’s own masking:

{"hook": "guardrail", "stage": "input", "texts": ["..."], "model": "alias", "team_id": "team-id"}

and answers {"action": "allow"}, {"action": "deny", "reason": "label"} or {"action": "redact", "texts": ["...one replacement per text..."]}. On the input stage a redaction rewrites the request text in place, before any external guardrail service sees it; a denial answers 400 guardrail_blocked. On the output stage (and in streamed windows under guardrail_streaming) the answer is not rewritten, so deny and redact both withhold it like a block, logprobs and stored Responses answers included (Held rewrites). The contract is the same for WebAssembly and JavaScript plugins. A trap, a JavaScript program_error, a refused load or a malformed verdict follows on_error. What the client can force - text above extensions.max_input_bytes, a concurrency refusal, a deadline, the memory or output limit - always fails closed, whatever on_error says.

Every execution writes one row (GET /api/v1/admin/extensions/executions): runtime (wasm or javascript), hook, plugin, version and module digest, team, key, outcome (ok, timeout, memory_limit, output_limit, trap, exit_nonzero, program_error, refused_concurrency, refused_team_concurrency, load_refused, runtime_disabled…), verdict, duration, HTTP calls and refusals, output size. Never the input, the output or a secret. Records are kept extensions.audit_retention_days (default 30) and pruned in the background. Lifecycle actions (upload, submit, approve, reject, activate, bind, secret changes) go to the administrative audit as extension.*.

Language How Status here
Go GOOS=wasip1 GOARCH=wasm go build with the SDK in extensions/sdk/go/aigw Built and run by the test suite (extensions/examples/go-guardrail and the adversarial test plugin)
TinyGo The same Go source: tinygo build -target=wasip1 -opt=z -no-debug -o plugin.wasm (needs wasm-opt from binaryen) Example built here with TinyGo 0.44.0 and wasm-opt 133 (1.2 MB module); kept as test data and run by the suite, including its redaction
AssemblyScript extensions/sdk/assemblyscript/aigw.ts; asc assembly/index.ts -o plugin.wasm --runtime stub --use abort= -O3 Example built here with AssemblyScript 0.28.20; the module is kept as test data and run by the suite
Rust extensions/examples/rust-guardrail: RUSTFLAGS="-C target-feature=-reference-types" cargo build --release --target wasm32-wasip1 Example built here with rustc 1.100.0 (64 KB module); kept as test data and run by the suite
JavaScript QuickJS-ng compiled to WebAssembly (github.com/fastschema/qjs v0.0.6, MIT), pinned by SHA-256 88fcbeead33cca3ec8394feb0fb3eec8047ec9ac5062aba7a63799cee11989b7, under extension_javascript Run by the suite; used by MCP code mode and by JavaScript plugins (extensions/examples/javascript-guardrail, run by the suite)
Python, ML libraries, own databases Out of process: an HTTP service called by the generic guardrail API (provider.type: generic_api); see Out-of-process plugins Example extensions/examples/python-guardrail, run in a container against the gateway binary by an opt-in test

Native shared-library plugins are not supported: they need CGO, do not work on Windows, require the exact toolchain and dependencies and cannot be unloaded.

Python is not run inside the sandbox. What Python brings - ML models, PII libraries, a team’s own database - needs a full interpreter, native extensions and memory well beyond a guardrail call, so it runs as your own HTTP service and the gateway calls it with the existing generic guardrail API. Nothing new is added to the gateway: no flag, no protocol, no process started by the gateway.

extensions/examples/python-guardrail is a complete service with the same rules as the sandbox examples (deny the code name, redact TCK-123… tickets), using only the Python standard library, with a Containerfile pinned by digest (Python 3.14.10 on Alpine), a non-root user and a health check. Replace its check(texts) with your own logic.

Terminal window
cd extensions/examples/python-guardrail
IMAGE=$(docker build -q -f Containerfile .)
GUARD_API_KEY=change-me docker run -d --name python-guardrail -p 127.0.0.1:8080:8080 -e GUARD_API_KEY "$IMAGE"
Variable Default Meaning
GUARD_PORT 8080 Listen port
GUARD_HOST 0.0.0.0 Listen address
GUARD_API_KEY empty (no check) When set, a request without this value in x-api-key gets 401
GUARD_MAX_BODY_BYTES 4194304 Larger requests get 413
GUARD_DELAY_SECONDS 0 Test hook only: wait before answering

Point a guardrail at it; the gateway sends the key from api_key_env as x-api-key:

guardrails:
- id: python-policy
name: Python policy
mode: block
stages: [input]
provider:
type: generic_api
endpoint: http://python-guardrail:8080/check
api_key_env: GUARD_KEY # the same value as GUARD_API_KEY
apply_redactions: true # apply the redacted texts (default false: advice only)
timeout: 2s # this check's deadline, 100ms-30s (default 5s)
on_error: block

What it receives and answers. POST /check with {"input_type": "request" | "response", "texts": [...], "request_data": {"user_api_key_team_id", "user_api_key_alias", "user_api_key_end_user_id"}, "model", "call_id", "trace_id"} (plus additional_provider_specific_params when params is set), already masked by the local detectors. It answers 200 with {"action": "BLOCKED"}, {"action": "NONE"} or {"action": "GUARDRAIL_INTERVENED", "texts": [...]}. GET /health answers 200 {"status": "ok"} for the container health check or a Kubernetes probe; it never reads texts. The service logs method, path and status only, never texts or headers.

Redaction. The example answers GUARDRAIL_INTERVENED with the redacted texts, as the generic API defines. By default the gateway treats them as advice and lets the request through unchanged. With apply_redactions: true it applies them: on input each text replaces the one sent, in place (roles, tool calls and structure unchanged); on a non-streaming answer (stage output) they replace the visible text, and a change to reasoning, a transcript or a tool call, an answer with token logprobs or a stored Responses answer withholds the answer (Held rewrites). The answer must carry exactly one string per text sent, in the same order, each at most twice the original plus 4,096 bytes; anything else is a failure that on_error decides. A streamed window cannot be rewritten, so a redaction ends the stream like a block. Use on_error: block with it: with allow, a check that does not finish lets the original through. See Generic guardrail.

Timeouts and failures. Each check has a deadline in the gateway: the guardrail’s timeout, from 100ms to 30s, default 5s. The deadline cancels the call. A service that answers later, refuses the connection, answers a status other than 200 or an unknown action is a failure, and on_error decides: block (the default) answers 503 and nothing reaches the provider; allow lets the request through and logs the failure. Guidance:

  • Keep the service well under the deadline (a p99 of a few hundred milliseconds), and give your own model or database calls a deadline shorter than the guardrail’s timeout, so a slow dependency becomes a clear answer instead of a gateway timeout.
  • Choose on_error per guardrail: block for policy and compliance checks, allow only where availability matters more than the check.
  • Run more than one replica behind a Service and use /health for readiness; one stopped replica then costs no failed checks.
  • On the output stage, answers longer than 100,000 characters are withheld (502) without calling the service, whatever on_error says.

Tested here. TestPythonGuardrailExampleOverGenericAPI (internal/deploytest, opt-in with GATEWAY_T058_PYTHON_GUARDRAIL=1, needs Docker) builds the image, runs it in containers and puts the real gateway binary, with PostgreSQL, in front of it: deny (400), redaction in the service answer with the request passing unchanged without apply_redactions and redacted with it, on the request and on the answer, allow, a service slower than the deadline (the default 5 s and a guardrail timeout: 1s) and a stopped service, each failure with on_error: block (503) and allow (200). All its containers and its image are removed afterwards.

Instantiate plus call of a guardrail, measured on an Apple M4 Pro (go test ./internal/extensions -bench Guardrail):

Plugin 1 KiB of text 64 KiB of text
Go example (standard toolchain, 5 MB module; Go runtime start-up, encoding/json, regexp) 3.1 ms 69 ms
AssemblyScript example (10 KB module; substring check) 0.10 ms 3.9 ms
Rust example (64 KB module; substring check) 0.12 ms 1.3 ms
TinyGo build of the Go example (1.2 MB module; encoding/json, regexp redaction) 0.82 ms 15 ms
JavaScript example (1 KB source on QuickJS; RegExp redaction) 1.9 ms 25 ms

The standard Go toolchain’s WebAssembly start-up dominates small calls; for hot paths prefer Rust or AssemblyScript, or TinyGo when the plugin is Go (about 4x faster than the standard toolchain on the same source). A JavaScript plugin pays a fresh QuickJS instance and a parse of its source on every call (about 1.7 ms before any work) and then runs interpreted: the 64 KiB case is the regular expression replacing about 3,000 tickets. A JavaScript program with three host calls runs in about 1.3 ms.

extensions:
trusted_keys: [] # {id, public_key (base64 Ed25519)}; boot trust only
max_module_bytes: 16777216 # 1024-67108864
max_memory_pages: 1024 # 1-16384 pages of 64 KiB per call
max_timeout_ms: 1000 # 1-30000 per call
max_input_bytes: 1048576
max_output_bytes: 1048576
max_concurrency: 32 # calls per replica
team_max_concurrency: 4 # calls per team per replica
audit_retention_days: 30 # execution records
http:
max_calls: 4
timeout_ms: 2000
max_response_bytes: 262144
allow_loopback_http: false
allowed_private_cidrs: []

Every value is a ceiling: a plugin manifest may ask for less, never more. 0 takes the default.

Key Default What it does
extensions.trusted_keys [] Ed25519 keys (id, base64 public_key) that verify plugin signatures; removing one makes every version it signed refuse to load
extensions.max_module_bytes 16777216 Largest uploaded module, 1024 B–64 MiB
extensions.max_memory_pages 1024 A plugin’s linear memory per call, in 64 KiB pages, 1–16384
extensions.max_timeout_ms 1000 Deadline of one call, 1–30000 ms; the call is interrupted when it passes
extensions.max_input_bytes 1048576 Largest input handed to the sandbox, 1 KiB–16 MiB
extensions.max_output_bytes 1048576 Largest output a plugin may return, 1 KiB–16 MiB
extensions.max_concurrency 32 Calls one replica runs at once, 1–4096; past it a call is refused at once and counted, never queued
extensions.team_max_concurrency 4 Calls of one team per replica, 1–4096 and at most max_concurrency
extensions.audit_retention_days 30 How long execution records are kept, 1–3650 days
extensions.http.max_calls 4 http_call host calls one plugin call may make, 1–64
extensions.http.timeout_ms 2000 Deadline of one http_call, 100–30000 ms
extensions.http.max_response_bytes 262144 Largest http_call response body, 1 KiB–16 MiB
extensions.http.allow_loopback_http false Lets http_call reach a loopback HTTP address, for local testing
extensions.http.allowed_private_cidrs [] Up to 16 private networks http_call may reach; the destination must also be in the signed manifest and the team binding

Restart to apply. The code_mode sub-block is described in MCP code mode.

Settings → Extensions shows the runtime (trusted key fingerprints, every ceiling including the HTTP and code mode ones, this replica’s outcome counters), each plugin with its versions (each marked WebAssembly or JavaScript), signature verdicts, load status and team bindings, and the recent executions with their runtime. Global administrators upload, approve with a signature, activate and roll back; team administrators submit versions, bind plugins to their teams and set write-only secrets. The upload form takes a .wasm module or, when the manifest says "runtime": "javascript", a .js file that it sends as source. Viewers and operators read.

Every route below needs a console session or an admin Bearer token, the role’s permission and, for writes, the X-CSRF-Token header; the full contract is in the API reference.

Route What it does
POST /api/v1/admin/extensions/{id}/activate Makes an approved version the active one (install, upgrade or rollback), or deactivates the plugin
POST /api/v1/admin/extensions/{id}/rollback Reactivates the previous version
POST /api/v1/admin/extensions/{id}/versions/{version}/approve Approves a pending submission with the reviewer’s signature by a trusted key
POST /api/v1/admin/extensions/{id}/versions/{version}/reject Rejects a pending submission
PUT /api/v1/admin/extensions/{id}/bindings/{team} Binds a plugin to a team and sets its allowed egress
DELETE /api/v1/admin/extensions/{id}/bindings/{team} Removes a team’s binding and its secrets
PUT /api/v1/admin/extensions/{id}/bindings/{team}/secrets/{name} Stores a write-only team secret for the plugin, encrypted
DELETE /api/v1/admin/extensions/{id}/bindings/{team}/secrets/{name} Removes a team’s secret

m7gtw[email protected]