.env
1. Create the machine
exec(mid, cmd) below is a thin wrapper around client.machines.executions.create that polls until succeeded/failed and returns stdout. See the reference repo for the 15-line helper.
2. Install OpenClaw into persistent storage
Root fs is small and ephemeral. Redirect everything npm writes (prefix, cache, tmp) into/home/machine/.
3. Configure, then launch the gateway
Enable the HTTP endpoint before starting the gateway or you restart it.setsid is how you detach: the execution API waits on foreground processes, and nohup & alone inherits the session.
4. Chat
model is an agent target. Override the backing LLM with x-openclaw-model: anthropic/claude-sonnet-4-6. Streaming with "stream": true. Sessions share history by user.
Full reference
openclaw.ts end-to-end + chat.ts replayer.