Architecture
Security Guarantees
Memory Isolation
WASM tools run in linear memory completely isolated from the host:- Default limit: 10 MB per tool
- No heap access: Cannot read host memory
- No pointers: Cannot access arbitrary addresses
- Bounds checking: All memory accesses validated by WASM runtime
ResourceLimiter:
CPU Metering
WASM execution is fuel-metered to prevent infinite loops and CPU exhaustion:- Fuel: Virtual “gas” consumed per WASM instruction
- Default limit: Configurable per tool (typically millions of instructions)
- Epoch interruption: Periodic checks for timeouts
- Tokio timeout: Hard wall-clock limit (default 30s)
No System Access
WASM tools have zero system access by default:- ❌ No filesystem (no WASI FS imports)
- ❌ No raw sockets
- ❌ No subprocess spawning
- ❌ No environment variable access
- ❌ No system clock (host provides
now_millis())
Fresh Instances
Each tool execution creates a fresh WASM instance:- Compile once: WASM binary validated and compiled at load time
- Instantiate per execution: New memory, new store, new state
- No state reuse: Previous execution’s memory is discarded
- Side-channel prevention: No shared state between executions
Capability System
All WASM tools start with zero capabilities. Each must be explicitly granted:Available Capabilities
Capability Configuration
Capabilities are defined in*.capabilities.json files:
HTTP Capability
The most sensitive capability. Enforces:- Host allowlisting: Only approved domains
- Path restrictions: Specific API endpoints only
- Method controls: GET/POST/etc. per endpoint
- Rate limiting: Requests per minute/hour
- Size limits: Max request/response body sizes
- HTTPS enforcement: No plaintext HTTP
- Credential injection: Secrets added by host, not WASM
Secrets Capability
Tools can check existence but never read plaintext:Workspace Capability
Read-only access to workspace files with prefix restrictions:ToolInvoke Capability
Indirect tool access via aliases (prevents direct tool enumeration):Security Constraints
Host Functions (V2 API)
WASM tools interact with the host via these functions:Logging
Time
Workspace Read
HTTP Request
Secret Exists
Tool Invoke
Failure Modes
WASM Trap
If WASM code traps (invalid memory access, division by zero, etc.):- Execution stops immediately
- Instance is discarded (never reused)
- Error returned to caller
- No host state corruption
Fuel Exhaustion
Memory Limit Exceeded
Capability Denied
Best Practices
For Tool Authors
- Request minimal capabilities: Only what you need
- Use tight allowlists: Specific hosts and paths
- Handle errors gracefully: Capability denials, rate limits
- Avoid secrets in logs: Use
secret_exists()checks - Respect fuel limits: Optimize expensive operations
For System Administrators
- Audit capabilities.json: Review all granted permissions
- Monitor logs: Watch for denied requests (potential attacks)
- Rotate secrets: Use
expires_atfor temporary credentials - Set conservative limits: Start with low fuel/memory, increase if needed
- Keep allowlists tight: Only domains you trust
Source Code References
- WASM runtime: src/tools/wasm/runtime.rs
- Capabilities: src/tools/wasm/capabilities.rs:1-200
- Resource limits: src/tools/wasm/limits.rs
- Host functions: src/tools/wasm/host.rs
- Allowlist validation: src/tools/wasm/allowlist.rs:74-164
See Also
- Network Security - HTTP allowlisting and rate limiting
- Credential Management - Secret injection at boundary
- Security Overview - Complete security architecture