DEV Community

Cover image for I let developers run arbitrary code on my cloud platform. Here's everything that broke.
Harun - solo dev
Harun - solo dev

Posted on

I let developers run arbitrary code on my cloud platform. Here's everything that broke.

I built HYNA-Stage to give developers ephemeral cloud environments in seconds. I let users run arbitrary code, push to GitHub, and spin up runtimes on demand.

For the first few weeks, it was a disaster.

I am a 12-year-old solo dev building entirely on a $150 Android phone in Termux. I don't have a massive AWS budget or a team of SREs watching dashboards. When things broke, they broke quietly, and they broke expensively (in compute limits).

Here is exactly what broke, how I found it, and the rules I wrote to stop it from happening again.

The Zombie Apocalypse

My first version of the platform let sandboxes "pause" when a user's session timed out. It seemed efficient. Why boot a whole MicroVM again if we can just freeze it?

Users would close their browser tabs and walk away. The sandbox stayed "paused" in the cloud. I checked my usage logs and realized I had dozens of zombie VMs consuming resources for users who had gone to sleep. I was burning my free-tier compute limits on ghosts.

The Fix: I stopped being clever. Sandboxes now hard-kill at creation.

Sandbox.create({ 
  timeoutMs: 1800 * 1000, 
  lifecycle: { onTimeout: "kill" } 
});
Enter fullscreen mode Exit fullscreen mode

But users close tabs without logging out, so I added a pg_cron job that runs every 5 minutes to sweep the database and flip any row still marked running past its TTL to expired. If it's not actively being used, it's dead.

🏎 The Race Condition (The "Infinite" Quota)

I built a quota system: 3 concurrent sandboxes per user. I wrote a function that checked if the user had less than 3, returned true, and then provisioned the VM.

Then I realized: if a user fires 10 parallel requests at the exact same millisecond, all 10 requests check the count (which is 0), all 10 get true, and all 10 provision VMs. My boolean check was decorative.

The Fix: I had to make the check and the claim atomic. I use a Postgres advisory lock to serialize requests per user, and I write a pending reservation row inside the same transaction.

PERFORM pg_advisory_xact_lock(hashtextextended(p_user_id::text, 0));
-- Check limits, then INSERT reservation row immediately.
Enter fullscreen mode Exit fullscreen mode

Now, parallel requests queue up. The first three get in; the next seven get a 429 Too Many Requests before a single VM is ever booted.

🀫 The Silent Lie (Inference Engine)

To make the CLI easy, I built an inference engine that reads your package.json and guesses your runtime. It worked great for standard repos.

Then a tester named Abdullah pointed out the failure mode: if you have a non-standard monorepo, the engine guesses wrong, provisions the wrong VM, and fails silently. The user stares at a broken environment wondering what they did wrong.

The Fix: I am adding a --dry-run flag. Before provisioning, the CLI will print exactly what it guessed (runtime, start command, port) and ask for confirmation. It fails loudly instead of silently starting the wrong thing.

βœ…Stuff That Actually Worked

It’s not all horror stories. Two architectural decisions saved my life:

  1. Firecracker MicroVMs over Docker: When I realized users could run arbitrary code, I panicked about container escapes. Switching to hardware-virtualized MicroVMs (via E2B) meant every user gets their own kernel. If they break out, they only break out of their own tiny VM. It costs me 7 seconds of cold-start time, but I sleep at night.
  2. ETag Polling over Webhooks: I needed GitHub hot-reload. Webhooks require managing public URLs for thousands of temporary VMs. Instead, the sandbox just polls the GitHub API for the file's ETag hash. If the hash changes, it runs git reset --hard. It costs almost zero bandwidth and requires no routing infrastructure.

How I Run It Now (The Rules)

After these failures, I established rules for the platform. They are hardcoded, not just in my head:

  1. "Done" means the URL returns 200. Not "the VM booted," not "the build passed." The CLI waits until the port is actually listening.
  2. No persistent state. If you didn't push to Git before the TTL, your code is gone. I will not build a snapshot system to save users from their own forgetfulness.
  3. Unrestricted egress is a known gap. Sandboxes currently have open outbound network access. I put a warning directly next to the setup instructions on my site. I will not pretend the network is isolated until I build the allowlist.

❓ The Question for You

I am still figuring out the edge cases of ephemeral infrastructure.

If you were designing a system where users can run arbitrary code for 30 minutes and then the environment is destroyed forever, what is the one failure mode you would be most terrified of?

Drop it in the comments. If it's something I haven't thought of, I'll build a fix for it this week.

β€” Harun, Founder & CEO, HYNAWEB 🐯☁️

Top comments (6)

Collapse
 
xulingfeng profile image
xulingfeng •

I enjoyed this one. The zombie sandboxes and the quota race condition are painfully familiar engineering lessons, haha. What I appreciate most is that you didn't just patch things quietly. You explained what went wrong and what you learned from it. That's how real engineering experience is built. Keep experimenting, and keep sharing the messy parts too. They're often the most interesting. β˜•

Collapse
 
koda2026 profile image
Harun - solo dev •

xulingfeng β€” honestly, this comment means a lot coming from you. Your earlier one is the reason this post exists. I went and studied the homepage posts the way you suggested, realized I'd been writing manuals instead of stories, and rewrote how I explain the failures.

The zombie VMs and the quota race were the two I was most embarrassed about. Writing them down publicly felt like a bad idea, and it turned out to be the best one.

So thank you β€” for the reality check first and the encouragement second. I'll keep the messy parts coming. β˜•οΈπŸ―

Collapse
 
xulingfeng profile image
xulingfeng •

Haha, then I'm glad you took that advice and ran with it. And honestly, those embarrassing failures are often the best stories to tell. Nobody learns much from a perfect-looking project. Keep writing in your own voice, Harun. I'll be looking forward to the next chapter. β˜•

Thread Thread
 
koda2026 profile image
Harun - solo dev •

"Nobody learns much from a perfect-looking project" β€” that's the line I'm keeping. I used to think the failures were the part to hide. Turns out they're the only part worth reading.

Appreciate you sticking around for the next chapter. It's a weird one: a bilingual health tracker for Tamil Nadu school kids, and the scariest bug wasn't in the code at all. β˜•πŸ―

Collapse
 
syedfahads profile image
Syed Fahad •

the ETag polling is a nice trick. if you send the ETag back as If-None-Match with a token, GitHub's 304s don't count against your rate limit, which helps once lots of sandboxes poll at once

Collapse
 
koda2026 profile image
Harun - solo dev •

Spot on, Syed. The If-None-Match header is the unsung hero here.

Without it, N sandboxes polling every 5 seconds would torch the GitHub rate limit in minutes. Those free 304s are exactly what make this polling architecture viable at scale, instead of just a neat trick that breaks in production.

Appreciate you calling out the scaling cliff β€” it's the exact edge case I'm watching for as more testers jump in. 🐯