---
title: "Washlet — Cluster Hosts for wasmCloud | wasmCloud"
description: "Washlet is the wasmCloud cluster host — a lightweight Wasm runtime daemon that runs WebAssembly components on Kubernetes nodes inside host pods."
canonical: "https://wasmcloud.com/docs/runtime/washlet/"
---

Version: v2

# Cluster Hosts (Washlet)

### Run a wasmCloud host as a cluster node connected to the operator mesh.

A **washlet** is a cluster-connected host: a `ClusterHost` from the `wash_runtime::washlet` module. Unlike a standalone `Host` (covered in [Building Custom Hosts](https://wasmcloud.com/docs/runtime/building-custom-hosts/)), a washlet connects to the wasmCloud operator mesh via NATS and receives workload commands from the scheduler. This is how the [Kubernetes Operator](https://wasmcloud.com/docs/kubernetes-operator/) deploys and manages workloads across a fleet of hosts.

## Standalone host vs. cluster host

|  | Standalone `Host` | `ClusterHost` (washlet) |
| --- | --- | --- |
| Managed by | Your application code | wasmCloud operator via NATS |
| Workload commands | Programmatic API (`HostApi`) | NATS subjects |
| Plugins | In-memory (dev) or custom | NATS-backed for production |
| Entry point | `HostBuilder` | `ClusterHostBuilder` |
| Use case | Embedding, custom integration | Operator-managed fleet |

## Running with `wash host`

The simplest way to run a washlet is the `wash host` CLI command. It connects to NATS and joins a host group, ready to receive workload commands from the operator.

shell

```shell
wash host --host-group my-cluster --scheduler-nats-url nats://nats:4222
```

### `wash host` flags

| Flag | Default | Description |
| --- | --- | --- |
| `--host-group` | `default` | Host group label used for workload scheduling |
| `--host-name` | (auto-generated) | Human-readable name for this host |
| `--scheduler-nats-url` | `nats://localhost:4222` | NATS URL for the control plane (workload commands) |
| `--data-nats-url` | `nats://localhost:4222` | NATS URL for the data plane (plugin backends) |
| `--http-addr` | (disabled) | If set, enables the HTTP handler on this address |
| `--postgres-url` | (disabled) | If set, enables the `wasmcloud:postgres` plugin (direct queries and prepared statements) |
| `--wasi-webgpu` | false | Enable the WebGPU interface |
| `--allow-insecure-registries` | false | Allow pulling from insecure OCI registries |
| `--registry-pull-timeout` | `30s` | Timeout for OCI pulls |
| `--scheduler-nats-tls-ca` | — | TLS CA for scheduler NATS. Setting it, or a client certificate, makes TLS **required** on that connection (since 2.12.0) |
| `--data-nats-tls-ca` | — | TLS CA for data plane NATS, with the same requirement |
| `--scheduler-nats-creds`, `--data-nats-creds` | — | Credentials file per connection, reread on every reconnect (since 2.12.0). `--*-nats-nkey`, `--*-nats-token-file`, and `--*-nats-user` with `--*-nats-password-file` are the alternatives |
| `--nats-ignore-discovered-servers` | false | Restrict NATS connections to their configured URLs rather than following cluster-advertised addresses (since 2.12.0). The Helm chart sets it on. Connections that require TLS (a TLS CA, a client certificate, or TLS-first) ignore advertised servers regardless, since 2.12.1 |

This table covers the core cluster flags; for the full and current flag surface, including the probe, drain, and memory flags and the socket and filesystem policy flags, see the [`wash host` command reference](https://wasmcloud.com/docs/wash/commands/#wash-host).

Each connection authenticates on its own, so a host can present one identity to the control plane and another to the data plane. A credential given as a **file** is reread on every connect, which is what makes a rotated Kubernetes Secret reach the next reconnect without a redeploy — mount it as a directory, without `subPath`, or the kubelet will not refresh it in place.

### Environment variables

`WASH_POSTGRES_URL` can be used in place of `--postgres-url`.

## Embedding programmatically

Use `ClusterHostBuilder` to embed a washlet in your own application. The builder mirrors `HostBuilder` but adds NATS-specific configuration:

rust

```rust
use std::sync::Arc;
use wash_runtime::{
    host::http::{Ingress, DynamicRouter},
    plugin::{
        wasi_blobstore::NatsBlobstore,
        wasi_config::DynamicConfig,
        wasi_keyvalue::NatsKeyValue,
        wasi_logging::TracingLogger,
        wasmcloud_messaging::NatsMessaging,
    },
    washlet::{ClusterHostBuilder, run_cluster_host},
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();

    // Connect to NATS (scheduler and data plane can be separate connections)
    let scheduler_nats = async_nats::connect("nats://localhost:4222").await?;
    let data_nats = async_nats::connect("nats://localhost:4222").await?;

    // Build the cluster host with NATS-backed plugins
    let mut builder = ClusterHostBuilder::default()
        .with_host_group("my-cluster")
        .with_nats_client(Arc::new(scheduler_nats))
        .with_plugin(Arc::new(DynamicConfig::new(true)))?   // true = NATS-backed
        .with_plugin(Arc::new(TracingLogger::default()))?
        .with_plugin(Arc::new(NatsBlobstore::new(&data_nats)))?
        .with_plugin(Arc::new(NatsMessaging::new(data_nats.clone())))?
        .with_plugin(Arc::new(NatsKeyValue::new(&data_nats)))?;

    // Optionally enable HTTP
    let http_router = DynamicRouter::default();
    let http_server = Ingress::new(http_router, "0.0.0.0:8080".parse()?).await?;
    builder = builder.with_http_handler(Arc::new(http_server));

    let cluster_host = builder.build()?;

    // Start the host and run until shutdown
    let shutdown = run_cluster_host(cluster_host).await?;

    println!("Cluster host running. Press Ctrl+C to stop.");
    tokio::signal::ctrl_c().await?;

    // Graceful shutdown
    shutdown.await?;
    println!("Host stopped.");
    Ok(())
}
```

### `ClusterHostBuilder` methods

| Method | Description |
| --- | --- |
| `with_host_group(str)` | Host group label for workload scheduling |
| `with_host_id(str)` | Assign the host ID before the host connects, so the embedder knows it up front (since 2.12.0). 1–128 ASCII letters, digits, hyphens, or underscores, since it forms one subject token. `host_id()` reads it back. Fallible: it returns `Result` |
| `with_host_name(str)` | Human-readable name (auto-generated if not set) |
| `with_nats_client(Arc<Client>)` | NATS client for the control plane |
| `with_plugin(Arc<dyn HostPlugin>)` | Register a plugin (IDs must be unique) |
| `with_http_handler(Arc<dyn HostHandler>)` | Register the HTTP handler |
| `with_host_builder(HostBuilder)` | Provide a pre-configured `HostBuilder` for advanced use |
| `with_artifact_cleaner(frequency, max_age)` | Clean up stale cached artifacts on a schedule |
| `build()` | Construct the `ClusterHost` |

> **Never reuse a host ID**
>
> `with_host_id` is for a host whose identity your own system already knows — a node name, a lease, an allocation record. The ID has to be unique among every host sharing a control plane, and must not be reused by a *later* host process: the operator may ignore heartbeats from a removed host's ID for an hour or more, so a reused ID can leave a healthy host looking dead. Derive it from something that is never recycled, not from a slot or ordinal.

### NATS-backed plugins

In cluster mode, use NATS-backed plugin implementations so that workloads can access shared state across hosts:

| Plugin | Type | Description |
| --- | --- | --- |
| Config | `DynamicConfig::new(true)` | NATS-backed runtime config (pass `false` for dev/in-memory) |
| Logging | `TracingLogger::default()` | Structured logging via `tracing` |
| Key-value | `NatsKeyValue::new(&nats_client)` | NATS-backed key-value store |
| Blobstore | `NatsBlobstore::new(&nats_client)` | NATS-backed blob storage |
| Messaging | `NatsMessaging::new(nats_client)` | NATS pub/sub messaging |

## Attaching control to a host you own

`ClusterHostBuilder` owns host construction: you hand it a `HostBuilder`, plugins, and an HTTP handler, and it builds, starts, and owns the `Host`. Since 2.11.0 `AttachedHostControl` inverts that, serving the same NATS control API for a host **you** built, started, and keep owning.

rust

```rust
use wash_runtime::washlet::{AttachedHostControl, HostCommandHandler, HostControlDefaults};

let control = AttachedHostControl::builder(host.clone(), nats_client)
    .with_host_group("my-cluster")
    .with_handler(Arc::new(MyPolicy))
    .attach()
    .await?;

// ... later, stop serving control while the host keeps running
control.shutdown().await?;
```

The builder also takes `with_heartbeat_interval` (zero means 15s), `with_max_concurrent_starts`, `with_artifact_cleaner(frequency, max_age)`, and `with_liveness`. Dropping the `AttachedHostControl` aborts the loop.

What this makes possible is **one host serving both locally-originated and operator-originated workloads**, with your code arbitrating which workloads the control plane may see or touch. A `HostCommandHandler` intercepts every remote `start`, `stop`, and `status`, and can refuse it, rewrite it, or delegate to `HostControlDefaults` for stock behavior:

rust

```rust
#[async_trait]
impl HostCommandHandler for MyPolicy {
    async fn start(&self, defaults: &HostControlDefaults, req: WorkloadStartRequest)
        -> anyhow::Result<WorkloadStartResponse> {
        if !req.workload_id.starts_with("owned-") {
            anyhow::bail!("admission denied");
        }
        defaults.start(req).await
    }
}
```

Nothing in the runtime distinguishes a locally-started workload from an operator-started one, so protecting one is the handler's job: `HostControlDefaults::stop` stops whatever `workload_id` it is given. Refuse a `stop` or `status` whose id your own code owns, as the example above refuses a `start`. What the runtime does guarantee is that only one attachment may be active at a time — a second is refused rather than silently layered over the first, so a handler's policy cannot be bypassed by attaching again.

Note that `with_host_group` sets the host group label in heartbeats only; it does not add a `hostgroup` label to the host itself. `ClusterHostBuilder` has no `with_handler`, so command interception means moving onto this path.

> **A new NATS permission, for restrictive auth only**
>
> Since 2.11.0 a host proves its control subscription is live before reporting started: it subscribes, publishes a marker to `runtime.host.<host_id>.__control.ready`, and waits to receive its own message back. The connection must therefore be allowed to **publish** to that subject and must not use `no_echo`. Failing either, startup fails after 10 seconds with a message naming the subjects, instead of a host that starts cleanly and silently serves no commands. The chart's bundled NATS applies no subject-level permissions, so a stock install is unaffected; this matters only where you have hand-rolled restrictive NATS authorization.

## How the operator communicates with washlets

The operator sends commands to washlets by publishing to NATS subjects:

```
runtime.host.<host_id>.workload.start
runtime.host.<host_id>.workload.stop
runtime.host.<host_id>.workload.status
runtime.host.<host_id>.heartbeat
```

Washlets publish heartbeats to:

```
runtime.operator.heartbeat.<host_id>
```

Messages are JSON-encoded. You typically don't interact with these subjects directly—the operator handles scheduling and the washlet handles command processing.

Since 2.12.1 the operator checks that a heartbeat's payload ID matches the ID in the subject it arrived on, and ignores the heartbeat otherwise. It also refuses to let a different ID claim an existing `Host` name. A name does not stay taken, though: once the old host has gone unheard-from for the heartbeat TTL (60 seconds, not currently configurable) and the operator is hearing the rest of the fleet, it deletes that `Host` itself, and the name is free. Delete the `Host` by hand only to free a name immediately, or while the old host is still running and heartbeating.

Both checks assume NATS permissions confine each host to its own heartbeat subject. One credential shared across a host group (`runtime.operator.heartbeat.*`) lets any host in the group publish a heartbeat as any other. Where the hosts in a group do not trust each other, give each its own credential and matching [`--host-id`](https://wasmcloud.com/docs/wash/commands/#wash-host) — which means one replica per host group, since the chart renders a single argument list for every replica in a group.

## Keep reading

- [Building Custom Hosts](https://wasmcloud.com/docs/runtime/building-custom-hosts/) - Embed a standalone host without NATS
- [Creating Host Plugins](https://wasmcloud.com/docs/runtime/creating-host-plugins/) - Build custom plugins for your host
- [Kubernetes Operator](https://wasmcloud.com/docs/kubernetes-operator/) - Deploy washlets managed by the operator
- [wash-runtime source code](https://github.com/wasmCloud/wasmCloud/tree/main/crates/wash-runtime/src/washlet) - `ClusterHost` implementation

Last updated on **Nov 9, 2026** by **Eric Gregory**
