Skip to content

Blog

Where Should Your AI Agents Live? Kubernetes vs. ECS vs. Everyone Else

My software factory is outgrowing two personal computers. Here is how EKS, ECS, plain servers, hosted sandboxes and the AI companies’ own cloud agents compare for hosting agent workers, on long-lived machines or a fresh sandbox per job.

Two trays of square tiles sit beside five individual enclosures, with a tilted copper-striped tile between them.Two trays of square tiles sit beside five individual enclosures, with a tilted copper-striped tile between them.
Workers can share a long-lived machine or start each job in a fresh sandbox.

Astrohacker Factory runs its worker agents on my personal computers. Each worker is a long-lived process that leases a job and runs one harness subagent, such as Claude Code, Codex or Grok, in a git worktree. Jobs also run builds and browser test suites. Running many workers in parallel uses a lot of compute, and it’s easy to saturate both machines. The logical place to grow is the cloud. I Built a Software Factory

I build Factory, so I have a stake in how this question gets answered. I’ve tried to keep what the vendors’ documentation says separate from my own reading of it. Every price, limit and latency below was checked on November 24, 2026, unless I give another date, and the sources are linked beside each claim. Prices change quickly. Hetzner alone raised prices several times this year. Hetzner’s statement

One fact that simplifies everything

Factory workers pull their work. A worker asks the factory for a job over HTTPS, clones from GitHub, and posts results back. Nothing needs to connect to the worker. Any machine or container that can reach the factory and GitHub can be a worker, behind a NAT, in a private subnet, or inside a sandbox with no public address. Astrohacker Factory

That rules out a whole class of problems. There are no load balancers, no ingress rules and no ports to open. The hosting question becomes a question about compute, isolation, state and credentials.

Two shapes, both valid

There are two reasonable ways to put workers in the cloud.

Long-lived worker machines. A cloud box runs several workers, the way my computers do today. Workers share a disk, caches and installed tools. Each job gets its own worktree, but jobs share the machine’s CPU, memory and network.

A fresh sandbox per job. Something creates an isolated environment for one job, a worker inside it leases that job, and the environment is thrown away when the job is done.

I don’t think one shape wins. They trade against each other:

  • Cost and utilization. A long-lived box costs the same whether it’s busy or idle, so it’s cheapest when you keep it full. A sandbox per job bills closer to what you use, which matters when work arrives in bursts.
  • Isolation. Worktrees separate files, not processes. On a shared box a runaway build or a confused agent can affect its neighbors, and every job can read whatever credentials are on the machine. A sandbox per job limits a bad job to its own environment.
  • Cold start. A warm machine starts a job in the time it takes to create a worktree. A sandbox has to boot, pull an image, install dependencies and clone the repository, unless you invest in images, snapshots or warm pools.
  • Persistence and pause. On a long-lived box, dependency caches, build output and browser binaries stay on disk between jobs. Sandboxes vary a great deal in what they keep when they sleep: nothing, the filesystem, or memory too.
  • Heavy builds and browser tests. Big shared machines handle bursts of compilation and headless Chrome well. Small sandboxes can run out of memory or hit size caps.
  • Operations. A fleet of boxes needs patching, monitoring and disk cleanup. Sandboxes move that to a provider or a scheduler, along with a new set of limits.
  • Credentials. This one is big enough to get its own section.

Both shapes fit the pull model. A long-lived box runs several workers that wait for jobs. A sandbox-per-job setup needs a small launcher that sees queued work, starts a sandbox, and lets the worker inside take one lease and exit. I don’t see a reason Factory couldn’t support both.

Subscriptions, not API keys

I assume a team running coding agents at volume buys many subscriptions, not per-token API access. For a startup, a $200-a-month plan for Claude Code, Codex or a similar harness is far more cost-effective than paying API rates for the same agent work. So the real question for each host is how a subscription-signed-in harness gets onto the machine and stays there.

Claude Code. claude setup-token runs the browser sign-in once and prints a one-year OAuth token for a Pro, Max, Ultra, Team or Enterprise plan. Anthropic documents it for “CI pipelines, scripts, or other environments where interactive browser login isn’t available.” You pass it as CLAUDE_CODE_OAUTH_TOKEN. An ANTHROPIC_API_KEY in the same environment takes precedence, which can quietly switch a worker to API billing. Ordinary logins expire, and using Claude Code doesn’t extend them. CLAUDE_CONFIG_DIR keeps several accounts apart on one machine. Claude Code authentication

Codex. The Codex CLI signs in with ChatGPT or an API key. On a headless machine you can use a device-code flow that’s in beta and has to be enabled first, or sign in elsewhere and copy ~/.codex/auth.json. OpenAI says to treat that file like a password, and Codex refreshes its tokens during use. For programmatic CI work, OpenAI recommends API keys. It also documents the auth.json pattern for trusted runners and access tokens for Business and Enterprise workspaces. Codex authentication and access tokens

Grok. xAI’s Grok Build CLI launched in May 2026 as an early beta for subscribers, with a headless mode for scripts. I found no documented headless sign-in. Grok Build

The two shapes handle these credentials differently.

On a long-lived machine, you sign each account in once and the credential lives on the disk, one config directory per account. Token refreshes happen in place. The cost is exposure: every job on that box runs next to every credential on it.

In a fresh sandbox, the credential has to be injected at each start, usually as a secret or environment variable. Claude Code’s long-lived token fits that well. A credential file that refreshes itself during use is harder: any refresh happens inside a sandbox you’re about to delete, so the current credential has to live somewhere outside it. The upside is that each job sees only the one credential it was given.

Then there are the terms. Anthropic says its advertised Pro, Max and Ultra limits “assume ordinary, individual usage of Claude Code and the Agent SDK.” Its Consumer Terms forbid sharing account logins and access “through automated or non-human means” except with an API key or “where we otherwise explicitly permit it.” Anthropic puts hosting Claude Code in sandboxes or agent infrastructure under the Commercial Terms, with each end user signing in with their own credentials. OpenAI’s terms forbid sharing account credentials too. Claude Code legal and compliance, Anthropic Consumer Terms and OpenAI Terms of Use

I found no vendor text that explicitly allows one company to run many individual consumer subscriptions as a fleet of unattended workers. The team and enterprise plans are the clearly sanctioned route for a company. My reading is that a subscription should belong to the person or seat it was bought for, and that it’s worth reading your plan’s terms before you put it on a server. None of that depends on where the server is.

Kubernetes on AWS (EKS)

Kubernetes now has a project built for this. kubernetes-sigs/agent-sandbox adds a Sandbox resource, a single stateful pod with a stable identity and persistent storage, plus templates, claims and warm pools of pre-started sandboxes. Isolation runtimes such as gVisor or Kata Containers are chosen through a RuntimeClass. Release v1.0.12 came out on November 20, and its API is still v1beta1. agent-sandbox, releases and Kubernetes blog, March 2026

Pause and resume exist, with a limit. Suspending a sandbox releases its pod but keeps its claim and volumes. Running processes and memory are lost unless you pair it with pod snapshots, which the project shows only in a Google Kubernetes Engine example. A paused agent on EKS comes back with its files, not its running session. agent-sandbox releases

On start time, the Kubernetes blog says a new pod adds about a second of overhead and that warm pools effectively remove it. Google says its managed version on GKE allocates 90% of sandboxes within 200 ms. That’s a vendor figure from a different cloud. Image pulls and node launches add to all of this, and an agent image with toolchains and Chrome is large. Google Cloud blog, May 2026

Strong isolation has hardware requirements. Kata with Firecracker needs a virtual machine inside the node, which on EC2 meant bare metal until February 2026. AWS now offers nested virtualization on several Intel instance families, while still recommending bare metal for latency-sensitive work. An AWS Builder Center post from April measured about 5 seconds per Kata sandbox on EKS and needed self-managed nodes. gVisor runs on ordinary nodes. AWS also announced Nitro Sandboxes for EKS this month, a VM per pod without nested virtualization. I couldn’t read the primary pages for its pricing and limits, so I’ll only note that it exists. EC2 nested virtualization, Secure agent sandboxes on EKS and InfoQ on Nitro Sandboxes

The money is mostly compute, plus a control plane at $0.10 an hour, about $73 a month, or $0.60 an hour on extended support. EKS Auto Mode adds a management fee that works out to roughly 12% of the instance price in AWS’s own examples. The bigger cost is people. Qovery, which sells a Kubernetes platform, estimates 20 to 60 engineer-hours a month to run self-managed EKS against 2 to 5 for ECS on Fargate. Those are its planning estimates, not measurements. EKS pricing and Qovery

Scheduling many workers is where Kubernetes shines. Karpenter provisions nodes from pending pods’ requests and packs pods onto them. AWS recommends memory requests equal to limits, and marking long jobs so consolidation doesn’t evict them halfway through. EKS best practices: Karpenter

Emergent is one team that chose this route. It reports running more than 30,000 concurrent agent environments as plain Kubernetes pods with its own warm pool. It puts its cost per environment at roughly a quarter to a third of microVMs. Those are its figures, on its workload. Emergent

Ups: both shapes on one platform, real bin-packing, a standard sandbox API, any isolation runtime you can install. Downs: the most operational work of any option here, a beta API, no memory-preserving pause on EKS, and strong isolation that depends on node types.

ECS on AWS

ECS has no control-plane fee. ECS pricing

Fargate runs each task in its own isolated virtual environment, which AWS moved onto Firecracker microVMs in 2018. You don’t manage servers. That makes it the lowest-effort way to get a sandbox per job on AWS. Fargate security and Firecracker announcement

The limits matter for agent work. A task tops out at 16 vCPU with up to 120 GB, or 32 vCPU with up to 244 GB, and 200 GiB of ephemeral disk. Fargate allows no privileged containers, no device mapping and no GPUs, and AWS notes this rules out Docker-in-Docker. Without devices there’s no /dev/kvm, so no nested virtualization. A job whose tests need Docker won’t run as is. Fargate task definitions and Fargate storage

AWS publishes no start-time figure for Fargate. It says image pull time is directly correlated with start time, and recommends lazy loading for images over 250 MiB. Fargate task definitions

At steady use, Fargate costs more. In us-east-1, x86 Fargate is about $0.0405 per vCPU-hour and $0.0044 per GB-hour. A 4 vCPU, 16 GB task running all month comes to about $170. An m7i.xlarge of the same size is about $147 on demand, and the ARM versions are about $136 and $119. That’s 14% to 16% more for Fargate before discounts, and an EC2 instance can hold several workers. The EC2 prices are from third-party trackers, because AWS’s pages didn’t load for me. Fargate pricing, DoiT: m7i.xlarge and DoiT: m7g.xlarge

ECS on EC2 fixes most of that. You pick the instance, including GPUs, pack several tasks per instance, and keep images cached. ECS Managed Instances, launched in 2025, has AWS patch and replace the instances for a management fee, and replaces each instance after 14 days. Self-managed capacity costs nothing extra and leaves the patching to you. ECS Managed Instances

AWS also sells Bedrock AgentCore Runtime, built for agents. Each session gets its own microVM for up to 8 hours, stops after 15 idle minutes by default, and can keep its filesystem. Images are arm64 only. CPU is billed at $0.0895 per vCPU-hour, but not while the agent waits on I/O, which suits a harness that spends much of its time waiting on a model. AgentCore sessions and AgentCore pricing

Ups: Fargate gives a VM per job with almost no operations. ECS on EC2 gives long-lived workers with less machinery than Kubernetes. Downs: no Docker or nested virtualization on Fargate, a premium at high utilization, and no warm-pool sandbox API like agent-sandbox.

Plain VMs and bare metal

The simplest option is the one I use now, moved to someone else’s building: rent a big machine and run several workers on it with worktrees.

Prices vary widely. For roughly 16 cores, Hetzner’s dedicated AX102 is €259 a month with 128 GB, and its CCX43 cloud server is €276.49 with 64 GB in Germany. Both are new-order prices after Hetzner’s June increase. OVHcloud’s ADVANCE-3 is $255 a month with 64 GB. A DigitalOcean CPU-Optimized droplet with 16 vCPU and 32 GiB is $336, and an EC2 c7i.4xlarge of that size is about $521 on demand. Hetzner cloud, Hetzner dedicated, OVHcloud Advance, DigitalOcean and Vantage: c7i.4xlarge

Bare metal also gives you /dev/kvm, so you can run Firecracker or Kata yourself and get a VM per job on a machine you pay for by the month.

Pere Villega described running Claude Code on a Hetzner box in April, reached over Tailscale with SSH closed to the internet. He estimates about 2 GB of memory per agent and hit out-of-memory kills on small machines. His prices predate Hetzner’s increase. madarco/agentbox packages the same idea as a tool that runs parallel agents in boxes on local Docker, Hetzner, E2B, Vercel and others. Running AI coding agents on Hetzner and agentbox

Ups: the cheapest compute per core, warm caches, no size caps, and the easiest home for a subscription sign-in. Downs: you run the machines, idle capacity costs the same as busy capacity, and jobs share a kernel unless you add a VM layer.

Hosted agent sandboxes

A crowd of providers now sells a sandbox per job as a product. The differences that matter are the isolation, what survives a pause, the size limits, and how they bill.

  • E2B uses Firecracker microVMs, and its infrastructure is open source and self-hostable. Pausing saves memory and the filesystem by default, taking about 4 seconds per GiB of memory, and resuming takes about a second. Paused sandboxes are kept indefinitely. Pro is $150 a month with sessions up to 24 hours, plus $0.0504 per vCPU-hour. Persistence, pricing and infra
  • Modal uses gVisor or an optional VM runtime, runs sandboxes for up to 24 hours, and has GPUs. Memory snapshots are in alpha and expire after 7 days. Sandboxes and snapshots
  • Daytona runs containers by default, with VM sandboxes that can pause with memory, and GPU sandboxes. It moved its production code to closed source in June 2026 and archived the public repository in October. Sandboxes and closed-source announcement
  • Cloudflare Sandbox gives each container its own VM, bills CPU only while active, and tops out at 4 vCPU and 12 GiB. After 10 idle minutes by default, files and processes are gone unless you back them up. Sandbox lifecycle and Containers pricing
  • Fly.io offers Machines you can stop and start, and Sprites, hardware-isolated VMs with a 100 GB persistent disk and filesystem checkpoints in about a second, billed on CPU and memory used. Sprites and pricing
  • Vercel Sandbox uses Firecracker, keeps the filesystem when a persistent sandbox stops, allows Docker inside, and runs up to 8 vCPU and 24 hours on Pro. Vercel Sandbox and pricing
  • Northflank runs CPU sandboxes in microVMs and GPU sandboxes in gVisor, on its cloud or yours. Sandboxes

I haven’t put cold-start numbers in that list. Nearly every figure in circulation, from tens of milliseconds to a few seconds, is a vendor claim, and the one “benchmark” I found lists numbers without a method. The comparisons I trust most say the same thing in different words. Upstash says cold start matters least. Fly.io says billing model matters more than headline rate. DigitalOcean says what survives idle differs more than price does. All three sell sandboxes, so weigh them accordingly. Upstash, Fly.io and DigitalOcean

For agent work, I agree with them. A coding agent waits on a model for most of its life, and a job lasts minutes to hours. A second of boot time is noise next to cloning, installing dependencies and warming a build cache. Whether a sandbox comes back with its caches, its browser binaries and a running session counts for much more.

Ups: a VM per job with almost no operations, pay for use, and pause features you’d spend months building yourself. Downs: size and time caps that can pinch builds and browser suites, per-hour rates above a monthly server at full use, and a credential injected into every sandbox.

The AI companies’ own cloud agents

The harness vendors run sandboxes too. Claude Code on the web, Codex cloud, Cursor Cloud Agents, GitHub Copilot’s cloud agent and Devin each take a task and run it in a managed VM inside that vendor’s product.

These are a different category from everything above. Claude Code cloud sessions run in a 4 vCPU, 16 GB VM and count toward your plan’s limits, with no separate charge for the VM. Codex cloud tasks use the ChatGPT plan allowance. Copilot’s agent bills in AI credits and caps Actions-based sessions at 59 minutes. Several now let you bring your own compute. Claude Code has self-hosted environments in beta for Team and Enterprise, Cursor has self-hosted workers, and Copilot can run on self-hosted Actions runners. Claude Code on the web, Codex cloud environments, Copilot cloud agent, Claude Code self-hosted environments and Cursor self-hosted

They’re the easiest way to get a sandbox per task, and the subscription question mostly answers itself, because the vendor runs its own harness under your plan. What you give up is the mix. Each runs one vendor’s agent under that vendor’s process. If Codex writes a change and Claude Code reviews it, with your checks between them, you’re running many harnesses under your own process, and that process needs a place to run. That’s the problem I built Factory around. Rent the Factory or Own It? and Is the Agent Platform of 2027 a Garden or a Factory?

Side by side

“Ops” is how much you run yourself. “Subscription fit” is how naturally a subscription-signed-in harness lives there.

Option Shape Isolation Cold start Persistence Cost model Ops Subscription fit
EKS + agent-sandbox Both Pods; gVisor or Kata ~1 s plus pulls; warm pools Volumes; no memory Nodes + $73/mo cluster High Secrets per pod
ECS on Fargate Per job VM per task Not published; image-bound 200 GiB, ends with task Per second, ~15% premium Low Inject per task
ECS on EC2 Both Containers; VM if 1 task/box Fast on warm box Instance disk EC2 (+ fee if managed) Medium Sign in per box
AgentCore Runtime Per session microVM per session Vendor-managed Filesystem option; 8 h max Per second, idle CPU free Low Inject per session
VMs / bare metal Long-lived Shared kernel unless you add VMs Instant on warm box Full disk Monthly Medium Easiest
Hosted sandboxes Per job Mostly microVMs; some gVisor Vendor-claimed ms–s None to memory, by provider Per second used Low Inject per sandbox
Vendor cloud agents Per task Vendor VM Vendor-managed Cached setup Included in plan Lowest Native, one vendor

Where I land

I don’t think there’s one answer, and I don’t think the two shapes compete.

If your work is steady and you want the cheapest compute, a few large servers running many workers each are hard to beat, and they’re the simplest home for subscription sign-ins. If your work is bursty, or you don’t want jobs sharing a machine with each other’s credentials, a sandbox per job earns its premium. Hosted sandboxes and Fargate get you there with the least effort. If you already run Kubernetes, or expect thousands of concurrent jobs, agent-sandbox gives you both shapes in one place, at the price of running Kubernetes.

The pull model means this choice isn’t permanent. A worker on a Hetzner box and a worker in a Firecracker sandbox ask the factory for work in the same way. You could start with one big machine, add sandboxes for untrusted or bursty jobs, and keep both. That’s the direction I want Factory to support.