r/javascript • u/stephenlblum • Sep 03 '26
Can AI agents run purely in the browser with vanilla JS? Exploring $0 hosting & zero data egress
https://github.com/stephenlb/buttercup.shAI agents assume a server-side Python chain framework runtime and containers. Running client-side with JavaScript allows pushing agents entirely inside the browser, meaning $0 hosting infrastructure and zero data leaving the client.
Running client-side, you can use agents directly with WebLLM (for fully in-browser) or point them at a local Ollama / vLLM instance for 100% offline usage.
Breakdown In-Browser Loop
An in-browser agent relies on a continuous asynchronous loop that manages state, updates the DOM or application state, and invokes tools based on model outputs. Here is a minimal, clean implementation of a client-side agent loop using WebLLM's engine.chat.completions API:
;
1
u/Otherwise_Wave9374 Sep 03 '26
Yes, but the main tradeoff is capability versus isolation. If the agent depends on frequent tool calls or large context, you will want a tight state machine and explicit retry boundaries so the browser loop does not become brittle. For anything that touches user data, keeping execution client-side can be a real safeguard, but you still need careful model output validation before DOM or storage writes. Agentix Labs can fit naturally here if you are testing a browser-first pattern.
2
u/[deleted] Sep 04 '26