Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 2 ๐Ÿ“– 4 min read

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-yea

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" } 
});

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.

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 ๐Ÿฏโ˜๏ธ

๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.