AI Agent Hosting: Where to Run Agents in Production
Eli Mernit12 min read
The right AI agent hosting depends on how long your agent runs and what it has to keep between runs. A long-running agent with files, tools and a shell needs a persistent VM. Code the agent writes belongs in a disposable sandbox. A short request-and-reply agent fits a managed runtime such as Amazon Bedrock AgentCore or Google's Agent Runtime, and an agent that mostly waits for events fits Cloudflare's Agents SDK.
The sections below compare those options on session limits, state, idle billing and price, with the inputs behind every cost.
What an AI agent hosting platform has to provide
An agent is a loop that calls a model, runs tools and repeats, so it holds a process open far longer than a web request does. A host built for stateless HTTP handlers will cut that loop off or forget what it did. Check five things before you pick one:
- Run length. One task can take minutes or hours. Look for the platform's hard cap on a single run, and for what happens when the cap is reached.
- State. Cloned repos, installed packages, browser profiles and half-finished work have to survive a restart. Some hosts keep a disk, some keep rows in a database, and some keep nothing unless you add a storage service.
- Isolation. An agent that executes code it wrote, or code from a prompt, needs a boundary around that code. Our guide to sandboxing AI-generated code covers the threat model.
- Credentials. The agent needs API keys, and a prompt injection can ask it to print them. A good host keeps the real key out of the agent's reach.
- Idle cost. Most agents wait more than they work. What you pay while the agent waits for a model reply, a webhook or a person decides the monthly bill.
GPUs are a sixth item only if the agent runs its own model. An agent that calls a hosted model API needs CPU and memory, not a GPU.
How to choose AI agent hosting by agent type
Match the host to the shape of the agent, then compare prices inside that group.
- A coding agent or dev-box agent that clones repos, installs packages and runs for hours: a persistent VM. It gets a real disk, a shell, Docker and no session cap.
- An agent that runs generated code as one of its tools: keep the agent where it is and send the code to a sandbox that is created per task and thrown away.
- A chat or support agent that answers in seconds to minutes and stores history in a database: a managed agent runtime, especially if the rest of your stack is already on AWS or Google Cloud.
- An event-driven agent that wakes on a webhook, a schedule or a WebSocket message and does a little work each time: Cloudflare's Agents SDK.
- A small always-on bot that holds one connection open all day: a small Fly Machine, an app platform such as Railway, or a fixed-price VPS.
AI agent hosting options compared
The table lists what each option runs, how long one run can last, what survives between runs, and what you pay while the agent is idle.
| Option | What it runs | Longest single run | State kept between runs | Billing while idle |
|---|---|---|---|---|
| Beam VM | Any Linux process, systemd services and Docker in a CPU microVM | No cap | Root disk after a stop; disk, RAM and processes after a pause | No compute while stopped or paused |
| Fly Machine | A Docker image as a Machine | No cap | Volumes only; the root filesystem resets | Stopped Machines pay for root filesystem storage |
| Amazon Bedrock AgentCore Runtime | Agent code in one microVM per session | 8 hours per microVM | Nothing by default; session storage and AgentCore Memory are add-ons | Session ends after 15 idle minutes by default |
| Google Agent Runtime | Agents built with ADK, LangGraph, LangChain, LlamaIndex, AG2 or custom code | Not listed on the pricing page | Sessions and Memory Bank services | Idle time between turns is not billed |
| Cloudflare Agents | A TypeScript class on a Durable Object | Event by event | SQLite storage built into each agent | Hibernating agents are not billed for duration |
| E2B sandbox | Any Linux process in a sandbox | 1 hour on Hobby, 24 hours on Pro | Filesystem and memory after a pause | Rates apply while the sandbox runs |
| Railway service | A container built from a repo or image | No cap | Volumes | Bills the CPU and memory the service uses |
Each row is explained in the sections that follow, with links to the vendor pages the figures come from.
Persistent VMs for long-running AI agents
A persistent VM is the closest thing to the laptop the agent was built on: a Linux machine with a disk, a shell and background services, which stays where the agent left it. It fits coding agents, browser agents and any agent that needs installed tools more than it needs fast scale-out.
A Beam VM is a named CPU microVM with its own kernel, systemd, SSH and a durable root disk. The default size is 4 vCPUs, 8 GiB of RAM and a 50 GiB disk on Ubuntu 24.04, and the disk can be set as high as 100 GiB. Everything on the root filesystem persists, including apt packages, Python environments and Docker images. This setup creates a smaller agent box that sleeps when nobody is using it:
# Store the model key; it is only released to api.anthropic.com
beam secret create ANTHROPIC_API_KEY "$ANTHROPIC_API_KEY" --host api.anthropic.com
# A 2 vCPU / 4 GiB VM on the Shared CPU tier with the secret bound
beam vm new agentbox --cpu-tier shared --cpu 2 --memory 4096 --secret ANTHROPIC_API_KEY
# Pause after 5 idle minutes, keep RAM, wake on the next connection
beam vm update agentbox --ttl 300 --idle-action pause --auto-resume
beam vm ssh agentboxThe --cpu-tier flag needs beam-client 0.2.236 or later.
Three details in that block matter for agents.
Pause keeps memory. Stopping a VM saves the disk and discards RAM. Pausing checkpoints RAM and running processes along with the disk, and resuming restores them, so an agent picks up mid-task. Both release compute, and a paused or stopped VM has no compute charge. With --auto-resume, an SSH session, an SDK call or a permitted request to one of the VM's URLs wakes it.
The idle timer watches connections, not processes. SSH sessions, SDK calls and open terminal or desktop sessions count as activity. A command running inside the VM on its own does not. For an agent that works unattended, turn the timer off with beam vm update agentbox --ttl 0, or hold a vm.keep_alive() lease from the Python SDK until the job is done.
The key never enters the VM. The VM sees a placeholder in $ANTHROPIC_API_KEY. Beam swaps in the real value only in HTTPS request headers sent to the hosts you approved, so an agent that is tricked into printing its environment prints the placeholder. Outbound network rules can also limit which hosts the VM reaches. Our post on running Claude Code unattended walks through that setup.
beam vm fork agentbox agentbox-2 copies the root disk into a second, independent VM, which is how you give ten agents the same prepared environment. Beam VMs are CPU-only; an agent that needs a GPU for part of its work runs that part in a sandbox or a deployed endpoint.
Fly Machines are the other common choice in this group. A Machine boots from a Docker image and has no session cap, but its root filesystem resets when the Machine restarts, so anything worth keeping goes on a volume. The cost section prices both for a small agent that runs all day.
Sandboxes for the code an agent writes
A sandbox is a disposable environment that is created for a task, runs code and is deleted. It doesn't replace the agent's host. The agent calls it as a tool, so a mistake or a malicious instruction in generated code stays inside something you were going to delete anyway.
Beam sandboxes boot in seconds, bill by the millisecond while they run and can attach a GPU. The Python default is 1 CPU, 128 MiB of memory and a 600-second lifetime, and keep_warm_seconds=-1 removes the lifetime. A sandbox runs in a container by default or in a microVM with use_vm=True.
E2B is the best-known sandbox service. Its sandboxes run continuously for as long as 1 hour on the free Hobby plan and 24 hours on Pro. Pausing a sandbox saves its filesystem and memory, and E2B's persistence docs say the runtime limit resets after a resume. E2B has no GPUs. We compare the two in more depth in the E2B alternatives guide.
Many production agents use both layers: a VM or runtime for the agent loop, and a sandbox per task for anything the model wrote.
Managed agent runtimes on AWS and Google Cloud
A managed agent runtime takes your agent code, gives each session its own isolated compute and handles scaling, identity and tracing. It suits teams that already run on that cloud and want the agent inside the same IAM, network and billing. The limits are shorter sessions and less control over the machine.
Amazon Bedrock AgentCore Runtime gives every session a dedicated microVM. Its session docs set two timers: a session's compute stops after 15 idle minutes by default, and one microVM lives for 8 hours at most. The next call to the same session gets a new microVM. Memory and disk are wiped when the compute stops unless you configure session storage, and longer-term recall goes through the separate AgentCore Memory service. Runtime bills per second on the CPU and memory a session consumes, and CPU isn't charged while the agent waits on I/O. The pricing page lists two generations: v1 at $0.0895 per vCPU-hour and $0.00945 per GB-hour, and v2 at $0.1276 and $0.0169, where v2 also reclaims idle memory after 120 seconds. The page doesn't say which generation a new runtime gets, so price your agent on both. Browser and code interpreter tools, the gateway and memory are billed separately.
Google's Agent Runtime, documented earlier as Vertex AI Agent Engine, deploys agents built with ADK, LangGraph, LangChain, LlamaIndex or AG2. It bills $0.085 per vCPU-hour and $0.009 per GiB-hour, rounded to the second, and the pricing page says idle time between turns is not billed. Sessions and Memory Bank are separate services with their own charges.
Both are a good fit for a chat or support agent with short turns. Neither gives you a machine you can SSH into, leave a build running on for two days, or install a desktop browser on.
Serverless agents on Cloudflare
Serverless hosting works for agents when the platform keeps state for you between invocations. A plain function platform does not, which is why a multi-step agent loop often outgrows it. Cloudflare's Agents SDK is the serverless option designed around that problem.
Each Cloudflare agent is a Durable Object: a TypeScript class with its own SQLite storage, WebSocket connections and scheduled tasks. The object is evicted after roughly 70 to 140 seconds without activity and wakes on the next request, message or alarm, with its state loaded back from SQL. Durable Objects pricing starts at the $5 a month Workers Paid plan, which includes 1 million requests and 400,000 GB-seconds of duration, and hibernating objects are not billed for duration.
That model keeps the bill low for thousands of mostly idle agents. The trade is that the agent is code written for Cloudflare's runtime. An agent that shells out to git, runs a Python environment or drives a browser needs a VM or a sandbox behind it.
App platforms and a plain VPS
An app platform or a VPS hosts an agent the same way it hosts any always-on service. This is the simplest route for a bot that holds a Slack, Discord or WebSocket connection open and keeps its state in a database.
Railway builds a container from your repo and bills per second for the CPU and memory it uses, at rates that work out to $20 per vCPU and $10 per GB of RAM over a month. The Hobby plan costs $5 a month and includes $5 of usage. Files persist only on volumes, at $0.15 per GB a month.
A fixed-price VPS is a low-cost way to keep a small box on all month, and many guides to running an agent 24/7 start there. You take on the operating system, process supervision, backups and firewall yourself, and every agent on the box shares one machine with no isolation between them unless you add it.
What it costs to host an AI agent 24/7
A small always-on agent costs between about $13 and $50 a month in compute at list prices, and an agent that sleeps between tasks costs a few dollars. Model usage is billed separately by your model provider and is usually the larger number.
| Host | Size priced | Hours billed | Monthly compute |
|---|---|---|---|
| Fly Machine, shared-cpu-1x | 1 shared vCPU, 2GB RAM | 720 | $12.70 |
| Beam VM, Shared tier | 1 vCPU, 2 GiB RAM | 720 | $15.84 |
| Railway service | 1 vCPU and 2GB RAM in full use | 720 | about $40 |
| Beam VM, Performance tier | 1 vCPU, 2 GiB RAM | 720 | $50.40 |
| Beam VM, Shared tier, paused when idle | 2 vCPU, 4 GiB RAM | 60 | $2.64 |
| E2B sandbox | 2 vCPU, 4 GiB RAM | 60 | $9.94 |
The inputs: Beam's Shared tier is $0.011 per vCPU-hour plus $0.0055 per GiB-hour for VMs up to 8 vCPUs and 16 GiB, and Performance, the default for new accounts, is $0.05 plus $0.01. So 1 vCPU with 2 GiB is $0.022 an hour on Shared and $0.07 on Performance, and 2 vCPUs with 4 GiB is $0.044 an hour on Shared. Beam storage isn't billed yet, and there are no egress fees. Fly's figure is its shared-cpu-1x preset with 2GB of RAM; a volume adds $0.15 per GB a month. Railway's figure assumes the service uses its full vCPU all month, and a mostly idle service bills less CPU. E2B's rate is $0.000014 per vCPU-second plus $0.0000045 per GiB-second, or $0.1656 an hour for 2 vCPUs and 4 GiB, and sessions longer than an hour need the $150 a month Pro plan.
For the always-on case the gap is small: $12.70 on Fly against $15.84 on Beam's Shared tier, and fixed-price VPS plans compete at that size too. The 60-hour rows are an agent that works about two hours a day. On a host that pauses with memory intact you pay for those hours only, and the agent still resumes where it stopped. Beam's Spot tier is cheaper again at $0.0063 per vCPU-hour plus $0.00135 per GiB-hour, but a Spot VM can be interrupted with 30 seconds' notice and has to be restarted by hand, so it suits batch runs more than a standing agent.
FAQ
What is AI agent hosting?
AI agent hosting is the infrastructure that runs an agent's loop in production: the process that calls the model, executes tools and keeps state between steps. It differs from ordinary web hosting because one task can run for minutes or hours, needs its files and memory to survive restarts, and may execute code that nobody reviewed.
Can I host an AI agent on a serverless platform?
Yes, if the platform stores state between invocations. Cloudflare's Agents SDK does this with a Durable Object and built-in SQLite per agent. A stateless function platform works for single-shot agents, but a long tool loop will run into its execution time limit and lose in-memory state between calls.
How do I host an AI agent 24/7?
Run it as a service on a machine that stays up: a persistent VM, a Fly Machine, an app platform or a VPS. Add a process supervisor such as systemd so it restarts after a crash, and keep its state on a disk or database that outlives the process. If the agent is idle most of the day, a VM that pauses and wakes on connection costs less than one that runs all month.
Do AI agents need a sandbox?
An agent needs a sandbox when it runs code it generated or code from an untrusted source. The sandbox is separate from the agent's own host, is created per task and is deleted afterwards. Agents that only call fixed APIs can skip it.
Do AI agents need GPUs?
Not usually. An agent that calls a hosted model such as Claude or GPT uses CPU and memory only. A GPU is needed when the agent runs an open-source model itself or does GPU work as a tool. On Beam that work goes in a GPU sandbox or endpoint, because VMs are CPU-only.
How much does AI agent hosting cost?
At list prices a 1 vCPU, 2GB always-on agent costs $12.70 a month on a Fly shared-cpu-1x Machine and $15.84 on a Beam VM on the Shared tier, both for 720 hours. A 2 vCPU, 4 GiB Beam VM on Shared that runs 60 hours a month and is paused the rest costs $2.64. Model API usage is extra everywhere.
Can AI agents run in my own cloud account?
Yes. Amazon Bedrock AgentCore and Google's Agent Runtime run inside your AWS or Google Cloud account by design. Beam offers bring-your-own-cloud, where compute is billed to your cloud account and Beam charges a management fee of $0.019 per vCPU-hour and $0.009 per GB of RAM per hour. For running the sandbox layer on your own hardware, see our guide to self-hosting a code sandbox.
Give your agent a machine that keeps its state
A Beam VM gives an agent a durable disk, SSH, Docker and a pause that keeps memory, billed per second while it runs. Create a Beam account and run the four commands above, or read more about Beam for AI agents. Current rates are on the pricing page.
