+-------------------+ +-----------------+ +-----------------+
| LLM-generated JS | --> | QuickJS WASM | --> | Host (Node) |
| (untrusted) | | sandbox | RPC | (trusted) |
+-------------------+ +-----------------+ +-----------------+
|
v
+-----------------------+
| UniFi APIs (HTTPS, |
| per-tenant TLS, |
| X-API-Key auth) |
+-----------------------+
The QuickJS WASM sandbox is the boundary between LLM-generated JavaScript and the host. The host is trusted; the sandbox is not.
- Read the OpenAPI operation index (
spec.local,spec.cloud) - Call host-defined functions:
unifi.local.<tag>.<op>(args),unifi.local.callOperation(...),unifi.local.request(...)(andunifi.cloud.*) - Use ECMAScript primitives, JSON, basic timers (no DOM/network/fs)
- Read process env or files
- Make outbound network calls (no
fetch, noXMLHttpRequest, nonode:http) - Spawn processes, load native modules, or escape the WASM heap
- See API keys, CA certificates, or any host-side secrets — credentials live in
TenantContexton the host
- Single-user mode: env vars validated at startup; the process holds them in memory.
- Multi-user mode: each request brings its own headers; the resulting
TenantContextis short-lived (request-scoped) and is garbage-collected when the request finishes. There is no inter-tenant cache of credentials. - Credentials are passed to
HttpClientconstructors and used for outbound HTTPS only. They never appear in MCP tool output (only call results do).
Each execute call is bounded by:
- Time — 30 s deadline via QuickJS interrupt handler
- Memory — 64 MB per-runtime (
runtime.setMemoryLimit) - Stack — 512 KB
- API calls — 50 calls per execute (
MAX_CALLS_PER_EXECUTE, configurable) - Code input — 100 000 chars
- Result size — 100 000 chars (truncated with notice)
- Logs — 1 MB / 1000 entries
- Outbound: HTTPS to the configured controller(s) and
api.ui.com. No proxying through the sandbox. - Inbound (HTTP transport):
/mcp,/health. Origin allowlist is configurable; rate limit is 60 req/min/IP by default.
Strict by default. Operators can opt in to:
- Custom CA:
X-Unifi-Local-Ca-Cert(PEM bundle) — TLS verification still runs, just against your CA. - Insecure:
X-Unifi-Local-Insecure: true— TLS verification skipped. Loud warning emitted in tool output. Not allowed on the Cloudflare Workers deployment.
See SECURITY.md.