From Zero to Production — A Complete Guide to Sandboxed, Portable Components
Introduction
- The Problem That Started It All
- What WASI Is and Why It Matters
- The Evolution: From Preview 1 to the Component Model
- What You Will Learn
- How to Use This Book
- Prerequisites and Assumptions
- Version Notes
- The Promise
Part I: Foundations
Chapter 1: Why WASI Exists — The Problem with Portable Execution
- The Container Paradox — Security vs Practicality
- Sandboxed Plugins — A Recurring Dream
- WebAssembly Leaves the Browser
- What WASI Promises
Chapter 2: WebAssembly Fundamentals
- A Stack Machine for the Modern Era
- The Module — WebAssembly’s Unit of Code
- Linear Memory and Its Constraints
- Imports, Exports, and Host Interaction
- Execution Model and Determinism
Chapter 3: From Browser to System — Enter WASI
- The Missing Piece — System Calls for WebAssembly
- Capability-Based Security Explained
- WASI vs POSIX — Design Philosophy
- Host and Guest — The Execution Boundary
- The WASI Preview 1 Era
Part II: Getting Started
Chapter 4: Tooling and Environment Setup
- Installing Wasmtime — The Reference Runtime
- Rust Toolchain for WASI Targets
- C/C++ with Clang and the WASI SDK
- Go WASI Support and Tooling
- JavaScript/TypeScript Compilation Paths
- Other Languages — AssemblyScript, Zig, Python, and More
- Installing wasm-tools
- Installing wit-bindgen
- Verifying Your Setup
Chapter 5: Your First WASI Programs
- Hello World in Rust — The Canonical Path
- Hello World in C — Using the WASI SDK
- Inspecting WebAssembly Modules with wasm-tools
- Running with Wasmtime — Flags, Permissions, and Output
- Debugging Your First Module
- Alternative Implementation Approaches
Chapter 6: Preview 1 Deep Dive — Understanding the Legacy API
- The Preview 1 Capability Model
- Filesystem Operations — Preopened Directories
- Standard I/O and Streams
- Clocks, Randomness, and Environment Variables
- Running Preview 1 Modules Today
Part III: The Modern WASI Stack
Chapter 7: WebAssembly Component Model — The Big Picture
- Beyond Modules — Why Components?
- Interfaces vs Implementations
- The Canonical ABI — Bridging Languages
- Resource Ownership Across Boundaries
- Component Composition and Linking
Chapter 8: WebAssembly Interface Types (WIT)
- WIT Syntax Basics — Packages and Interfaces
- Records, Variants, Options, and Results
- Strings, Lists, and Native Types
- Resources — The Key Abstraction
- Worlds — Defining Complete Environments
- Putting It All Together — A Complete WIT Example
Chapter 9: WASI Preview 2 — Components in Practice
- Preview 2 Architecture Overview
- New Capabilities via WIT Interfaces
- Streams and I/O as Resources
- Clocks, Randomness, and Configuration — Reimagined
- Running Preview 2 Components
- Migration Considerations from Preview 1
Chapter 10: Generating Bindings and Cross-Language Interop
- wit-bindgen — The Binding Generator
- Rust Bindings from WIT
- C Bindings and Header Generation
- JavaScript/TypeScript Bindings
- Composing Multi-Language Components
- Important Notes on Binding Tools
Part IV: Building WASI Applications
Chapter 11: Building Command-Line Applications
- Designing a Portable CLI in Rust
- Filesystem Operations — Reading, Writing, Traversing
- Environment Variables and Configuration
- Error Handling and Exit Codes
- Packaging and Distribution
Chapter 12: Networking and HTTP in WASI
- The State of Networking in WASI
- DNS Resolution (Where Available)
- HTTP Client Patterns
- Building an HTTP Server Component
- Limitations and Workarounds
Chapter 13: Resource Management and Host Capabilities
- Designing Custom WIT Interfaces
- Implementing Host Functions in Rust
- Resource Lifecycle and Cleanup
- Passing Capabilities Between Components
- Implementing a Custom WASI Host
Part V: Runtime Deep Dive
Chapter 14: Wasmtime — The Reference Implementation
- Wasmtime Architecture Overview
- CLI Usage — Permissions, Preopens, and Configuration
- Resource Limits and Sandboxing Controls
- Observability — Logging, Metrics, and Tracing
- Performance Tuning and Compilation Modes
Chapter 15: Embedding WebAssembly Runtimes
- Embedding Wasmtime in Rust Applications
- Instantiating Modules vs Components
- Provisioning Capabilities Programmatically
- Async Execution Models
- Lifecycle Management and Cleanup
Chapter 16: Other WASI Runtimes — Spin, WasmEdge, Wasmer
- Fermyon Spin — Serverless Components
- WasmEdge — Edge Computing and IoT
- Wasmer — Multi-Language Embedding
- Comparing Runtimes — Feature Matrix
- Choosing the Right Runtime
Part VI: Security and Sandboxing
Chapter 17: WASI Security Model in Depth
- Capability-Based Security — Theory to Practice
- The Least Privilege Principle in WASI
- Trust Boundaries and Attack Surfaces
- Sandboxing Guarantees and Limitations
- Sandbox Escapes — What Could Go Wrong
Chapter 18: Operational Security for Production
- Resource Limits — CPU, Memory, and File Descriptors
- Denial of Service and Exhaustion Attacks
- Secret Management and Environment Security
- Supply Chain Risks in WebAssembly
- Hardening Production Configurations
Part VII: Advanced Topics
Chapter 19: Runtime Internals — ABI, Memory, and Execution
- The Canonical ABI — Detailed Specification
- Memory Layout Across Language Boundaries
- Resource Tables and Handle Management
- Async Execution and Trampolining
- Component Instantiation Internals
Chapter 20: Performance, Profiling, and Benchmarking
- Understanding WASI Performance Characteristics
- Startup Latency — Causes and Mitigations
- Profiling Tools and Methodology
- Benchmarking Against Containers and Native
- Optimization Strategies
Chapter 21: Dynamic Plugin Architectures
- Plugin Architecture Patterns
- Discovering and Loading Components at Runtime
- Scoping Capabilities Per-Plugin
- Communication Between Host and Plugins
- Hot Reloading and Version Management
Chapter 22: Deployment at the Edge and in the Cloud
- WASI on Serverless Platforms (Cloudflare, Fermyon, etc.)
- Edge Computing with WASI
- Kubernetes and WebAssembly Runtimes
- Cold Start Optimization Strategies
- CI/CD for WASI Applications
Part VIII: Real-World Projects
Chapter 23: Project — Portable CLI Application Suite
- Requirements and Architecture Planning
- Implementation in Rust with WIT Interfaces
- Testing Across Platforms
- Security Hardening and Permissions
- Distribution and User Experience
Chapter 24: Project — Multi-Language Component System
- Architecture — Defining Shared Interfaces
- Implementing Components in Rust, C, and TypeScript
- Composing Components with wasm-tools
- Testing Cross-Language Communication
- Packaging as a Distributable System
Chapter 25: Project — Embedded Plugin Runtime
- Host Application Architecture in Rust
- Implementing Custom Capabilities
- Component Loading and Instantiation
- Async Plugin Execution
- Security Isolation Between Plugins
Chapter 26: Project — Production HTTP Service
- Service Architecture and Requirements
- Component Implementation with HTTP Support
- Observability — Logs, Metrics, Tracing
- Deployment Configuration
- Monitoring and Operations
Part IX: Reference and Roadmap
Chapter 27: Migration Guide — From Preview 1 to Preview 2
- Understanding the Breaking Changes
- Migrating Rust Applications
- Migrating C/C++ Applications
- Tooling and Workflow Changes
- Dual-Support Strategies
Chapter 28: Troubleshooting and Reference
- Common Compilation Errors and Fixes
- Runtime Errors and Their Meanings
- Debugging Techniques and Tools
- Compatibility Matrix — Languages, Runtimes, Features
- Quick Reference — Commands and Flags
Chapter 29: Glossary and Ecosystem Map
- Comprehensive Glossary of Terms
- The Bytecode Alliance and Governance
- Standards Bodies and Specifications
- Tooling Ecosystem Map
- Learning Resources and Community
Chapter 30: The WASI Roadmap — Where We’re Going
- Current Proposals in Flight
- Networking — The Next Frontier
- GPU and Hardware Acceleration
- Open Challenges and Research Directions
- Predictions for the Next Five Years
Conclusion
- The Journey from Zero to Production
- Key Takeaways
- When to Use WASI (and When Not To)
- Looking Forward