{"slug": "playing-a-gameboy-with-cloudflare-agents", "title": "Playing a Gameboy with Cloudflare Agents", "summary": "Developer rorz built an open-source Cloudflare Agent that controls a Game Boy Color emulator, publishing the code in the cloudflare-gameboy-agent GitHub repository. The project was prompted by Cloudflare job listings that let applicants fast-track applications by submitting an AI-powered application built on Cloudflare, and it uses the Cloudflare Agents SDK with a React/Vite starter, bun, tailwind, and the headless node-mgba emulator. The author framed the work as a hackathon-style demonstration of an unconventional use case for the Agents SDK beyond Cloudflare's documented Pi, Slack, and Browser agent examples.", "body_md": "[Posts](https://rorz.io/writing)\n\n# Playing a Gameboy with Cloudflare Agents\n\n### TL;DR\n\nI built a Gameboy Color emulator that Cloudflare Agents can control. It looks like this:\n\nThe [repo is here](https://github.com/rorz/cloudflare-gameboy-agent) if you'd like to check it out!\n\n## Hacker's mindset\n\nI was browsing the Cloudflare job listings earlier today and noticed that for some positions, they provide a way to fast-track your application by providing a link to an \"AI-powered application on Cloudflare\" that you've made.<sup>[1](#user-content-fn-1)</sup> It's pretty clear that they want you to make something that uses their [Agents SDK.](https://agents.cloudflare.com) I've been a big user of Cloudflare over the past ~1.5 years or so: my last startup, [Kenobi,](https://rorz.io/work/kenobi) went through Cloudflare's [sixth Startups cohort,](https://www.cloudflare.com/startups/workers-launchpad/) and I've made [lots of things on the side](https://rorz.io/work) with Cloudflare SDKs and hosted on their systems. But! I don't think I've actually used Cloudflare's Agents SDK yet.\n\n*This seems like a fun challenge...* I thought to myself. When I looked at the examples they give in [their docs](https://developers.cloudflare.com/agents/?utm_content=agents.cloudflare.com#example-agents) -- a Pi agent, a Slack agent, a Browser agent -- the examples are definitely real-world-relevant and *functional,* but they're perhaps a smidge... *pedestrian?*\n\nIf I apply a hacker's mindset here, i.e. pretending I'm at a hackathon, what are some cool use-cases that I would be intrigued by if I was working at Cloudflare and taking a look at people's applications? I started thinking if there was anything fun I could do [with Jev...](https://docs.typesafe.ai/introduction/coding-agents) But I think at this point just \"using Jev\" as a novelty is pretty overdone and not impressive on its own. It didn't take me long to start thinking about how other people had used Jev though (for inspiration), and the thought popped into my head that someone had gotten [Jev to play Pokémon Red](https://news.ycombinator.com/item?id=49845172) a couple of months ago. What about getting a Cloudflare agent to *play* Pokémon instead... What about getting one to play *any* game?\n\nI think it's quite fashionable at the moment to dream-up ways to [repurpose old hardware,](https://news.ycombinator.com/item?id=50440709) especially in the context of AI. Indeed, just a few days ago, someone posted about putting [ChatGPT on the SNES.](https://news.ycombinator.com/item?id=50568548) So with this in mind, I decided to set out and create a Cloudflare Agent that would be able to play a (virtual) Gameboy.\n\n## A blank slate, a *starter*\n\nTo kick things off, I used the [Cloudflare CLI quick start](https://developers.cloudflare.com/workers/get-started/guide/) in order to set up my `cloudflare-gameboy-agent` repo. I have to say that these days the sheer amount of options available when picking a starter is -- while helpfully encyclopaedic -- rather overwhelming!\n\nThis selection of options is *just* for the `Framework Starter` category:\n\nI chose the `React` starter, which sets up a Vite app. The boilerplate is a little intense, so I got rid of its assets and extraneous code, and switched to `bun` and `tailwind`.\n\nI had my blank slate!\n\n## Emulation\n\nI believe that the most productive and capable engineering happens when you either:\n\n1. Start with an end-to-end PoC *first,* and fill in the blanks*later.*\n2. Figure out the \"unknown\" technology first, before anything else.\n\nIn this particular case, the latter strategy is most relevant. I've built lots of AI agents before, and I know that I can design a cool-looking UI. But I have no idea how to put a games console emulator in the browser. A cursory Google search reveals that it is possible: I quickly stumbled upon the [`node-mgba`](https://arise-foundation.github.io/node-mgba/) project which is a headless Game Boy emulator for Node.\n\nI set Codex off to work on an initial plan: getting `node-mgba` to render frames somewhere and stream them in the browser somehow, using a ROM copy of Pokémon Red as our example game.\n\nCodex was quick to point out that `node-mgba` is a poor fit for us in Cloudflare Worker Land. Where possible we'd really rather prefer a web-compatible option, it reminded me. It found a WASM implementation of `mgba` [on GitHub here](https://github.com/wasm-gaming/mGBA-wasm) and applied a patch<sup>[2](#user-content-fn-2)</sup> to it in order to fix an interaction bug.\n\nAfter a few minutes, it had a square sitting in the middle of an otherwise blank page, which booted up slowly.\n\nWe had successfully perforated our webpage to reveal a playable GameBoy emulator.\n\n## CSS-as-an-Artform\n\nI knew that in order for this demo to be impressive, the UI had to be as fun (and cool) as possible. I'm a big fan of [extreme artistic implementations](https://github.com/cyanharlow/purecss-lace) of CSS: there's essentially [no limit](https://cssdoom.wtf/) to what you can do with it.\n\nSo, I asked Codex to take my childhood Gameboy Color, the [classic translucent purple](https://en.wikipedia.org/wiki/Game_Boy_Color#/media/File:Game-Boy-Color-Purple.jpg) one:\n\nAnd make it Cloudflare-ified... On its first pass, it came up with this:\n\nWhich I thought was pretty good!\n\nI didn't want to completely rip off both Nintendo's and Cloudflare's trademarks though, so I asked it to rebrand it as a `Cloudboy Color` instead.\n\nWhen attempting to refine a complex UI element, something that I find useful is -- after a first pass -- to get the model to break any reference imagery up into sections (or quadrants in this case) so that it has more points of detail to reference further and compare against.\n\nI also noticed that the circuit board behind the translucent shell was lacking: it was quite flat and basic. So I got it to scrutinise the circuitry in the Gameboy Color such that it could generate far more accurate SVGs of the internals.\n\nAfter some back and forth, we landed here:\n\nI was suitably impressed with `GPT Sol 6.2 Max`'s output for this. It didn't really take as much tuning on the UI as I'd have thought. One of the things that *did* require a lot of passes though was the [D-pad.](https://en.wikipedia.org/wiki/D-pad) Admittedly, I still don't think the D-pad is quite right, but I'm going to come back to that another time. The principal issue with it was that Codex wasn't sufficiently imagining how to draw the D-pad's rocker switch mechanics in CSS.\n\nOn the initial design, when I pressed `Left` for example, it was doing this:\n\nSo I tried to explain how a rocker switch mechanic *should* look (its \"gutter\" should be static), and we ended up somewhere a lot better.\n\n## Read-Only [App] Memory\n\nOne of the things I didn't really want to do was host or link to real, copyrighted ROM files, because of the obvious legal implications and risks of doing so. I think the most powerful and impressive public demos are ones that are frictionless: meaning, that if I wanted to create something *truly great* (in my opinion) then I'd have to bundle a ROM file with a hosted demo. In this particular instance, I'm less bothered about hosting this project -- more doing this write-up for it. I don't *really* want to host it anyway because hosting it would mean providing access to an agent, and therefore tokens.\n\nThese two reasons -- ROM legality and token usage -- are a big part I think of why *Jev Plays Pokémon Red* or [*Gemini plays Pokémon*](https://blog.jcz.dev/the-making-of-gemini-plays-pokemon) are streamed (on Twitch) instead of being web apps people can go and use. You only need to run one instance yourself in order to stream something like this to (>) millions of people, even also allowing them to interact with it.\n\nI did think about a streaming angle here, and I think I may still do that. But I've only budgeted spending a few hours on this idea. For now, you can [clone the repo](https://github.com/rorz/cloudflare-gameboy-agent) for yourself and provide a ROM file or URL easily.\n\n## Bring in the Agents\n\nNow that we had a fun, interactive Gameboy Color emulator wrapped up in a cool orange shell, it was time to do the thing we started this whole endeavour to do: bring in the AI agent control layer.\n\nWhat I wanted was fairly simple. I thought it would be best to have a side-panel that allowed you to connect the gameboy to an AI agent. You could play the emulator as a human, and then whenever you felt like it you could connect to an agent loop (powered by Cloudflare Agents in the worker) which would make automated, LLM-predicted moves.\n\nThe first pass, UI-wise here, looked relatively fine.\n\n*This is promising!* I thought. However, after turning it on I quickly realised that the agent wasn't really interacting with the game in the right way. I'd given Codex a *carte blanche* on how to approach hooking up an agent (and which model to use), and it had gone with Gemma 4, which was ostensibly \"button mashing\" its way through the screens.\n\nWhen I told Codex about this, it recommended `Opus 5.5` because Anthropic [has written](https://www.anthropic.com/research/components-of-agent-memory) about evaluating Claude's ability to play *Pokémon Red.* I thought this suggestion was heavy-handed in terms of cost, especially since somebody was able to get it to sort of work with Jev (as well as Gemini 2.5 Pro last year). I asked Codex to draw me a cost table up of how much, usage-wise, this would likely entail:\n\n| Model | Input / output per 1M tokens | Cost per turn | Cost per 1,000 turns | \n|---|---|---|---|\n| [Gemma 4 26B A4B](https://developers.cloudflare.com/workers-ai/models/gemma-4-26b-a4b-it/) · current | $0.10 / $0.30 | $0.00013–$0.00021 | $0.13–$0.21 | \n| [Qwen 3.8 27B](https://developers.cloudflare.com/workers-ai/models/qwen3.8-27b/) | $0.45 / $3.20 | $0.00077–$0.00205 | $0.77–$2.05 | \n| [Claude Sonnet 5.5](https://developers.cloudflare.com/ai/models/anthropic/claude-sonnet-5.5/) | $2 / $10 | $0.003–$0.007 | $3–$7 | \n| [Claude Opus 5.5](https://developers.cloudflare.com/ai/models/anthropic/claude-opus-5.5/) | $4 / $20 | $0.006–$0.014 | $6–$14 | \n\nI asked it to try Qwen instead, which it paired with Cloudflare's [`Clef Omni.`](https://developers.cloudflare.com/workers-ai/models/clef-omni/) This particular incarnation seemed capable of only zealously, relentlessly pressing `A` again-- now I knew this almost definitely wasn't the model's fault; there was something up with the way we were setting up our prompts and harness.\n\nI asked Codex to go and read [Joel Zhang's excellent write-up](https://blog.jcz.dev/the-making-of-gemini-plays-pokemon) on doing the same thing with Gemini, which uncovered that we weren't passing prior game state back to the agent. After hardening the control loop to wait and check its proposed inputs against the game state before proceeding, it finally started pressing `→`!\n\nThe elation was short-lived because after that initial nudge to the right, the decision-making halted again (reaching its internal timeout). It turns out that Codex was **mocking** the interactions(!!) in order to \"test\" the corrected decision logic.\n\nI told Codex to remove all of its Pokémon-specific mocks so that I can be sure the new decision model actually works. I'd also been sending some async prompts about fixes I wanted to see in the UI in the meantime, so things were looking much less \"plain\" from a UI perspective in the Agent side panel.\n\nAfter it finished up and then let me try for myself, things still didn't feel right. Our implementation with Qwen just wasn't able to make sane decisions about movement through the scene.\n\nIn the interest of time -- and because I wanted to produce something I could record a demo video of -- I decided to bump the underlying model to `Sonnet 5.5` *just* to see if [the Bitter Lesson](https://en.wikipedia.org/wiki/Bitter_lesson) held true with my harness. I still also had Codex reiterate on the logic side a bit more, and left it to play the game for a while by itself in order to iron out any more creases it could find in the gameplay loop.\n\nIt pains me to say<sup>[3](#user-content-fn-3)</sup> that Sonnet fixed most of my worries here. It's still not *perfect* though and when I did a play test through the first couple of game scenes, I had to nudge our character out of certain \"doom loop\" situations, such as being unable to determine how to exit a house.\n\n## Where next?\n\nI'm pretty happy -- after just a few hours' work -- where this ended up. I got the demo that I wanted: a Cloudflare Agents-controlled Gameboy emulator. Sure, the experience (with the current decision logic) isn't *amazing* but a lot of that is because I'm choosing much more cost-efficient models.\n\nWould I stream this? Sure! But I'm not planning to stream it just at the moment. I'm currently travelling around South East Asia so I'd rather not have to maintain a 24/7 Twitch stream of something that lots of people have already done.\n\nIf you want to check out the repo and deploy it to Cloudflare yourself you can do so here: [https://github.com/rorz/cloudflare-gameboy-agent](https://github.com/rorz/cloudflare-gameboy-agent)\n\nThanks for reading!\n\n## Footnotes\n\n1. \nThe full text reads: We plan to fast track candidates who complete an assignment to build a type of [AI-powered application](https://agents.cloudflare.com/) on Cloudflare. An AI-powered application should include the following components:\n  - LLM (recommend using Llama 3.3 on Workers AI), or an external LLM of your choice\n  - Workflow / coordination (recommend using Workflows, Workers or Durable Objects)\n  - User input via chat or voice (recommend using Pages or Realtime)\n  - Memory or state\n Find additional documentation [here](https://developers.cloudflare.com/agents/) .*Note: AI-assisted coding is encouraged, but you have to submit prompt history.*[↩](#user-content-fnref-1)\n2. \nCodex's response about this: I patched the mGBA browser wrapper’s frame scheduler because Pokémon Red froze after the first click in the in-app browser. The scheduler used `AudioContext.currentTime` to decide whether to pace the game by audio. If that clock kept moving while the audio worklet stopped draining samples, the scheduler saw a full queue and stopped advancing the game.The patch tracks actual sample consumption. After **500 ms** without progress, it advances the game using elapsed time. It also caps the audio queue at roughly**90 ms** so suspended audio can’t build up a backlog.I verified that the game kept advancing and keyboard input worked after clicking. Bun reapplies the patch on install. [↩](#user-content-fnref-2)\n3. \nNot because I dislike Sonnet -- Sonnet is great. Just because I really *wanted* to create something with a lower-cost model. But sadly didn't have enough time here.[↩](#user-content-fnref-3)", "url": "https://wpnews.pro/news/playing-a-gameboy-with-cloudflare-agents", "canonical_source": "https://rorz.io/writing/playing-a-gameboy-with-cloudflare-agents", "published_at": "2026-11-24 11:12:48+00:00", "updated_at": "2026-11-24 11:43:02.223270+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-products"], "entities": ["Cloudflare", "Cloudflare Agents SDK", "rorz", "node-mgba", "Kenobi", "Codex", "Game Boy Color"], "also_reported_by": [], "takeaway": "A Cloudflare Agent can drive a headless node-mgba Game Boy emulator, showing the Agents SDK can be wired to non-LLM tooling rather than only the documented Pi, Slack and Browser examples.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/playing-a-gameboy-with-cloudflare-agents", "markdown": "https://wpnews.pro/news/playing-a-gameboy-with-cloudflare-agents.md", "text": "https://wpnews.pro/news/playing-a-gameboy-with-cloudflare-agents.txt", "jsonld": "https://wpnews.pro/news/playing-a-gameboy-with-cloudflare-agents.jsonld"}}