---
title: "How to Run Untrusted Code Safely"
description: "Containers share the host kernel, so truly untrusted code such as AI-generated scripts or user submissions needs hardware isolation, allowlist-based network egress control enforced from outside the sandbox, rollback and multiple runtimes."
url: "https://swe.quest/articles/how-to-run-untrusted-code-safely-e25a4476701c9dc9"
canonical: "https://fly.io/blog/running-untrusted-code/"
source: "Fly.io"
published: "2026-02-02"
difficulty: "medium"
kind: "How-to"
reading_minutes: 3
tags: ["sandboxing","virtualization","security","ai-agents"]
---

# How to Run Untrusted Code Safely

A post on [Fly.io](https://swe.quest/sources/flyio.md), published 2026-02-02, 3 min read, How-to. Original: [https://fly.io/blog/running-untrusted-code/](https://fly.io/blog/running-untrusted-code/)

## Summary

Containers share the host kernel, so truly untrusted code such as AI-generated scripts or user submissions needs hardware isolation, allowlist-based network egress control enforced from outside the sandbox, rollback and multiple runtimes. Fly.io's Sprites meet these requirements. A code runner is set up with a deny-all network policy applied through the external API, which code inside cannot change even as root, and specific domains can be selectively allowed. Broken environments are recovered by destroying the Sprite or restoring a checkpoint in about a second.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Sandboxing & isolation](https://swe.quest/tags/sandboxing.md) (Security)
- [Virtualization](https://swe.quest/tags/virtualization.md) (Infrastructure)
- [Security](https://swe.quest/tags/security.md) (Security)
- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)

## Prerequisites

- containers basics ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))
- REST APIs ([easy posts on API design](https://swe.quest/tags/api-design.md?difficulty=easy))

## Keywords

Fly.io, Sprites, NIST SP 800-190, MITRE ATT&CK

## Related posts

- [What is an AI code sandbox?](https://swe.quest/articles/what-is-an-ai-code-sandbox-ff77320ddef8f884.md): Modal · 2025-07-24 · Easy · 9 min read · Sandboxing & isolation, AI agents, AI for coding, Containers
  AI code sandboxes are ephemeral, isolated environments for executing LLM-generated code so hallucinated packages, crashes or prompt-injected exploits can't affect the host or other tenants.
- [The Untrusted Autonomous Workload: How AI Coding Agents Reshape What Isolation Has to Do](https://swe.quest/articles/the-untrusted-autonomous-workload-how-ai-coding-agents-reshape-what-isolation-af433bee97ff8809.md): Docker · 2026-05-26 · Medium · 16 min read · Sandboxing & isolation, Virtualization, AI agents, Containers, Supply chain security
  AI coding agents are untrusted, autonomous workloads that containers were never designed to isolate, so Docker Sandboxes runs each agent in a microVM (custom VMM on Hypervisor.framework, WHP or KVM) with its own kernel and private Docker Engine.
- [Building Agents that Don't Break Themselves](https://swe.quest/articles/building-agents-that-don-t-break-themselves-946af945ee4733ac.md): Fly.io · 2026-06-08 · Medium · 6 min read · AI agents, Sandboxing & isolation, Identity & auth, Virtualization
  Separate where an agent lives from where it executes code: keep the agent loop on a durable host and send every shell command to a disposable Sprite sandbox.
- [Agent Swarms on Sprites](https://swe.quest/articles/agent-swarms-on-sprites-839304324464381c.md): Fly.io · 2026-02-09 · Medium · 3 min read · AI agents, Sandboxing & isolation, AI for coding
  Running each coding agent in a swarm on its own Sprite (a Fly.io sandboxed machine) avoids the shared-filesystem, conflicting-dependency and blast-radius problems of co-located agents.
- [Why AI Agents Need Isolation](https://swe.quest/articles/why-ai-agents-need-isolation-2e7b1a6342af3236.md): Docker · 2026-07-01 · Easy · 9 min read · Sandboxing & isolation, AI agents, Virtualization, Containers, AI for coding
  AI coding agents that run commands, install packages and handle credentials should execute behind an isolation boundary rather than directly on the developer's host.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
