Skip to main content

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:
string
First-party component name from the official registry.Format: namespace/component-name (e.g., trailbase/auth_ui)Must contain only alphanumeric characters, _, -, or /
string
HTTPS URL pointing to a .wasm or .zip file.Format: https://example.com/component.wasmOnly HTTPS is supported for security reasons
string
Local filesystem path to a .wasm or .zip file.Format: ./path/to/component.wasm or /absolute/path/component.zip

Adding Components

components add

Install a WASM component from a name, URL, or local path.
string
required
Component reference (name, URL, or path).
Components are installed to <data-dir>/wasm/ directory and are automatically loaded on server startup.
Installation process:
  1. Download/read component file(s)
  2. Extract (if ZIP archive)
  3. Validate WASM component format
  4. Copy to <data-dir>/wasm/
  5. 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.
string
required
Component reference. Can be a name or local path. URLs are not supported for removal.
This permanently deletes the component file(s) from disk. The operation cannot be undone.
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.
Example output:
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.
Example output:
Output structure:
string
Component package name.
string
Component namespace. First-party components use trailbase, custom components use custom namespaces.
string | null
Semantic version of the component, if specified.
string[]
List of WASI worlds the component implements.
string[]
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.
Example output:
Update process:
  1. Scan <data-dir>/wasm/ for installed components
  2. Identify first-party components by filename
  3. Download latest version for each
  4. Replace existing files
  5. Skip custom/third-party components
Only first-party components from the official registry are updated. Custom components must be updated manually.
Components are replaced in-place. If the download fails partway through, you may need to reinstall manually.

Component Structure

WASM Component Format

TrailBase uses WebAssembly Component Model (WASI Preview 2):

Component Lifecycle

  1. Installation - Component copied to <data-dir>/wasm/
  2. Discovery - TrailBase scans wasm/ directory on startup
  3. Loading - Components are loaded into WASM runtime
  4. Execution - Components respond to requests based on their interfaces
  5. Unloading - Components are unloaded on server shutdown

Runtime Configuration

Configure WASM runtime via CLI options:
integer
Number of WASM isolates/workers. Defaults to CPU count.
string
Sandboxed filesystem root for WASM components.

First-Party Components

trailbase/auth_ui

Pre-built authentication UI component. Installation:
Features:
  • Login page
  • Registration page
  • Password reset flow
  • Email verification
  • OAuth provider buttons
Interfaces:
  • login - Render login page
  • register - Render registration page
  • reset-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:
  1. Define interfaces using WIT (WebAssembly Interface Types)
  2. Implement in your language (Rust, Go, C, etc.)
  3. Compile to WASM Component using wasm-tools
  4. Install via CLI
Example WIT definition:

Component Requirements

requirement
Must use WASI Component Model (not core WASM modules).
requirement
Must be .wasm file or .zip containing .wasm files.
requirement
Must export at least one interface that TrailBase can invoke.
requirement
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
Solutions:

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

Packaging Components for Distribution

Managing Multiple Component Versions

Batch Component Operations

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 from trailbase/* namespace:
  • Built and signed by TrailBase team
  • Reviewed for security
  • Version-matched to TrailBase release
  • Automatically updated via components update

Third-Party Components

Third-party components run with the same privileges as first-party components. Only install components from trusted sources.
Before installing third-party components:
  1. Review source code if available
  2. Check developer reputation
  3. Test in development environment first
  4. Monitor resource usage
  5. Review WASM interfaces with components installed

Component API Reference

WASI Interfaces

TrailBase provides these WASI interfaces to components:
interface
Sandboxed filesystem access within --runtime-root-fs.
interface
Cryptographically secure random number generation.
interface
Access to system clocks for timestamps.
interface
Standard I/O streams.

TrailBase Interfaces

TrailBase-specific interfaces for components:
interface
HTTP request handling (in development).
interface
Database access (in development).
Component API is under active development. Check documentation for the latest available interfaces.