Overview
TrailBase supports WebAssembly (WASM) components for extending server functionality. The CLI provides commands to add, remove, list, and update WASM components.Component Management
Component References
WASM components can be referenced in three ways:First-party component name from the official registry.Format:
namespace/component-name (e.g., trailbase/auth_ui)Must contain only alphanumeric characters, _, -, or /HTTPS URL pointing to a
.wasm or .zip file.Format: https://example.com/component.wasmOnly HTTPS is supported for security reasonsLocal filesystem path to a
.wasm or .zip file.Format: ./path/to/component.wasm or /absolute/path/component.zipAdding Components
components add
Install a WASM component from a name, URL, or local path.Component reference (name, URL, or path).
Components are installed to
<data-dir>/wasm/ directory and are automatically loaded on server startup.- Download/read component file(s)
- Extract (if ZIP archive)
- Validate WASM component format
- Copy to
<data-dir>/wasm/ - Return list of installed files
First-party components are version-matched to your TrailBase installation. The URL template automatically uses your TrailBase version.
Removing Components
components remove
Remove an installed WASM component.Component reference. Can be a name or local path. URLs are not supported for removal.
URLs cannot be used for removal. Use the component name (for first-party components) or the local path instead.
Listing Components
components list
List all available first-party components from the official registry.This shows components available for installation, not currently installed components. Use
components installed to see installed components.components installed
List all currently installed components with their interfaces.Component package name.
Component namespace. First-party components use
trailbase, custom components use custom namespaces.Semantic version of the component, if specified.
List of WASI worlds the component implements.
List of interfaces exposed by the component.
The output filters out
wasi and root namespaces, showing only application-relevant interfaces.Updating Components
components update
Update all installed first-party components to the latest version matching your TrailBase installation.- Scan
<data-dir>/wasm/for installed components - Identify first-party components by filename
- Download latest version for each
- Replace existing files
- Skip custom/third-party components
Only first-party components from the official registry are updated. Custom components must be updated manually.
Component Structure
WASM Component Format
TrailBase uses WebAssembly Component Model (WASI Preview 2):Component Lifecycle
- Installation - Component copied to
<data-dir>/wasm/ - Discovery - TrailBase scans
wasm/directory on startup - Loading - Components are loaded into WASM runtime
- Execution - Components respond to requests based on their interfaces
- Unloading - Components are unloaded on server shutdown
Runtime Configuration
Configure WASM runtime via CLI options:Number of WASM isolates/workers. Defaults to CPU count.
Sandboxed filesystem root for WASM components.
First-Party Components
trailbase/auth_ui
Pre-built authentication UI component. Installation:- Login page
- Registration page
- Password reset flow
- Email verification
- OAuth provider buttons
login- Render login pageregister- Render registration pagereset-password- Render password reset page
More first-party components will be added in future releases. Check the registry with
trail components list.Custom Components
Creating Custom Components
Custom WASM components must implement WASI interfaces:- Define interfaces using WIT (WebAssembly Interface Types)
- Implement in your language (Rust, Go, C, etc.)
- Compile to WASM Component using
wasm-tools - Install via CLI
Component Requirements
Must use WASI Component Model (not core WASM modules).
Must be
.wasm file or .zip containing .wasm files.Must export at least one interface that TrailBase can invoke.
Runs in sandboxed environment with limited filesystem access.
Troubleshooting
Component Won’t Load
Error: Component file exists but isn’t loaded Solutions:Download Fails
Error:Failed to download component
Causes:
- Network connectivity issues
- Invalid URL
- Component not available for your TrailBase version
Version Mismatch
Error: Component loads but doesn’t work correctly Cause: Component version doesn’t match TrailBase version Solution:Permission Denied
Error:Permission denied when adding component
Solutions:
Component Conflicts
Error: Two components with same filename Solution:Advanced Usage
Component Development Workflow
Step-by-step: Develop and test custom component
Step-by-step: Develop and test custom component
Packaging Components for Distribution
Step-by-step: Create distributable component package
Step-by-step: Create distributable component package
Managing Multiple Component Versions
Managing component versions across environments
Managing component versions across environments
Batch Component Operations
Install multiple components at once
Install multiple components at once
Component Security
Sandboxing
WASM components run in a sandboxed environment:- No network access by default
- Limited filesystem access (only
--runtime-root-fs) - No system calls outside WASI
- Memory isolation between components
- CPU/memory limits enforced by runtime
Trusted Components
First-party components fromtrailbase/* namespace:
- Built and signed by TrailBase team
- Reviewed for security
- Version-matched to TrailBase release
- Automatically updated via
components update
Third-Party Components
Before installing third-party components:- Review source code if available
- Check developer reputation
- Test in development environment first
- Monitor resource usage
- Review WASM interfaces with
components installed
Component API Reference
WASI Interfaces
TrailBase provides these WASI interfaces to components:Sandboxed filesystem access within
--runtime-root-fs.Cryptographically secure random number generation.
Access to system clocks for timestamps.
Standard I/O streams.
TrailBase Interfaces
TrailBase-specific interfaces for components:HTTP request handling (in development).
Database access (in development).
Component API is under active development. Check documentation for the latest available interfaces.