AI agents · OpenClaw · self-hosting · automation

Quick Answer

Where to Host a Long-Running AI Agent With WebSockets

Published:

The short answer

Use Cloudflare Durable Objects when each user, room or session is its own agent; use Fly.io or Railway when you want an ordinary long-running server with no time limits; use Netlify Server if your app already lives on Netlify and your agent runs fit inside its 30-minute (Pro: 2-hour) request window. Render is a solid alternative to Fly.io and Railway with WebSocket support on web services. Limits and prices were read from each vendor’s documentation on November 22, 2026.

The comparison

Netlify ServerCloudflare Durable ObjectsFly.ioRailwayRender
ModelLong-lived Node.js process per instanceStateful object per ID, with SQLite storageFirecracker VM (“Machine”)Container serviceWeb service / background worker
WebSocketsYes; ~couple of hundred per instanceYes, with hibernation APIYesYesYes
Max request / connection30 min; 2 h on Pro, Business, EnterpriseNo wall-clock cap on connections; CPU time per request is limitedNoneNoneLong-lived connections supported
ScaleUp to 3 instances (1 on Free/Personal) in Early AccessMillions of objectsAutostop/autostart, scale to zeroReplicas (Hobby 5, Pro 42)Autoscaling on Pro
Cold startScales to zero after 5 min idle; 20 s to send headersMillisecondsMachine start on requestSleeps on Free onlyPaid instances stay up
PriceFree during Early Access; GA on GB-hour + vCPU-hourWorkers Paid $5/mo min; $0.15/M requests, $12.50/M GB-sFrom $2.19/mo (256MB); $6.70/mo (1GB)Hobby $5 min, Pro $20 min + per-second usagePro $25/mo + compute
Best forNetlify sites adding an agentPer-user agents, chat roomsAlways-on servers, any languageFast deploys with databasesTeams wanting managed PaaS

Why agents outgrow functions

An agent loop calls a model, waits seconds for it, calls a tool, waits again, and streams progress to the user the whole time. Netlify’s own launch post sums up the problem: a function spending ten seconds waiting on a model “occupies an entire instance for those ten seconds while doing almost nothing,” it cannot hold a WebSocket open, and state does not survive between invocations. A long-lived process serves many waiting requests from one event loop and keeps connection pools, caches and SDK clients warm.

Platform notes

Netlify Server (Early Access, launched November 10, 2026). A single entry file at netlify/server/index.ts — or an existing Express, Hono or Fastify app — becomes a server that deploys atomically with your frontend, with a server environment for every Deploy Preview. Instance sizes handle 32, 64 or 128 concurrent requests; open WebSocket connections are counted separately. Instances are replaced every 8 hours and get 90 seconds to drain on shutdown, and outbound connections close after 60 seconds idle — design clients to reconnect. Lifecycle hooks (onStart, onHealthCheck, onShutdown) let you warm up and drain job queues. It needs Netlify CLI 27.17.0 or later and a credit-based or Enterprise plan.

Cloudflare Durable Objects. Each object is a single-threaded actor with its own SQLite storage, addressed by ID — a natural home for “one agent per user”. Duration is billed in wall-clock time only while an object is active and not eligible to hibernate; with the WebSocket Hibernation API an idle connection costs nothing in compute, and incoming WebSocket messages are billed at a 20:1 ratio. Duration billing assumes 128MB per object. The Agents SDK builds on it — see best platforms for building and deploying AI agents.

Fly.io. Billed per second with no platform fee: $2.19 a month for a shared-cpu-1x 256MB Machine, $6.70 for 1GB, $13.39 for 2 CPUs and 2GB (Ashburn prices). Stopped Machines cost only $0.15 per GB of root filesystem, and autostop/autostart gives you scale to zero. Run Python, Go or anything in a container.

Railway. Pay per second for memory ($0.00000386 per GB-second) and CPU ($0.00000772 per vCPU-second), with the plan fee counting as usage credit. Hobby allows up to 48 vCPU and 48GB per service; Pro adds 42 replicas and a 99.99% availability target. Railway also sells isolated sandboxes for untrusted agent code.

Render. Web services accept inbound WebSockets and background workers suit queue-driven agents. Plans run Hobby $0, Pro $25 a month and Scale $499 a month, each plus compute.

Decision rule

  • Per-user state, many concurrent sessions, edge latency: Cloudflare Durable Objects.
  • Agent runs longer than 2 hours, or not in Node.js: Fly.io, Railway or Render.
  • Frontend already on Netlify, Node.js backend, runs under 2 hours: Netlify Server — but note it is Early Access with a 3-instance cap and unannounced GA pricing.
  • Durable multi-hour workflows that must survive restarts: add a durable execution engine — see best durable execution platforms for AI agents.

For streaming the agent’s output to the browser, see how to stream LLM responses: SSE vs WebSockets.

Last verified: November 22, 2026.

Sources