AI agent infrastructure is everything an agent needs beyond the prompt: a model (hosted API or your own GPU), an isolated place to run tools and code, state that survives between steps, a queue and orchestrator, a browser, scoped secrets, and tracing. The model is usually the biggest cost; the sandbox is the biggest risk.
- Core layers
- Model, sandbox, state, orchestration, browser, secrets, observability
- Typical agent task
- 10–30 model calls, 50k–300k input tokens
- Sandbox options
- Containers, gVisor, Firecracker microVMs, whole machines
- Firecracker boot time
- As little as 125 ms (published figure)
- Self-hosted 32B agent model
- Fits a 48 GB L40S at 4-bit
- Wandering Giants L40S
- $1.89/hr, billed by the minute
- Hosted vs own GPU
- Own GPU wins only when it stays busy
An AI agent is a loop: a model reads a goal, picks a tool, looks at the result and decides what to do next. Getting that loop to work on a laptop takes an afternoon. Running it for real users, thousands of times a day, with code execution, browsing, private data and a budget, is an infrastructure problem. This guide maps every layer of that infrastructure, what each one costs, and where a rented GPU fits.
What is AI agent infrastructure?
AI agent infrastructure is the set of systems an agent depends on to act in the world reliably: the model that makes decisions, the environment where its tools run, the storage that holds its state, the queue that schedules its work, and the controls that keep it safe and observable. The agent framework is the steering wheel. The infrastructure is the car.
The distinction matters because the framework is the easy part to change. Teams routinely rewrite their agent loop two or three times. The model server, sandbox fleet, secrets model and tracing take weeks to get right and decide whether the system is cheap, safe and debuggable.
A chatbot needs one thing: a model endpoint. An agent needs at least seven:
| Layer | What it does | Runs on | Typical choices |
|---|---|---|---|
| Model | Decides the next action, writes code and text | GPU (yours or a provider's) | Hosted API, or vLLM on a rented GPU |
| Tool execution | Runs code, shell commands, file edits | CPU, isolated | Containers, gVisor, Firecracker, E2B, Daytona, Modal |
| State | Holds files, memory, task history | Disk, database, object store | Postgres, Redis, S3-compatible storage, volumes |
| Orchestration | Queues tasks, retries, enforces limits | CPU | Redis + RQ or Celery, Temporal, a simple worker pool |
| Browser | Reads and operates websites | CPU (lots of RAM) | Playwright + Chromium, hosted browser services |
| Secrets and permissions | Lets agents act without holding raw keys | CPU | A tool proxy, scoped tokens, a vault, approval steps |
| Observability | Traces every step, token and cost | CPU | OpenTelemetry, Langfuse, structured logs |
Only the first row needs a GPU, and only if you host the model yourself. The rest is ordinary cloud engineering with unusual threat models. If GPU rental itself is new to you, start with what GPU cloud computing is and how it is billed.
Layer 1: the model — hosted API or your own GPU?
The model is the agent's brain and, in almost every agent system, its biggest running cost. You have two ways to get one: call a hosted API, or serve an open model on a GPU you rent.
A hosted API (OpenAI, Anthropic, Google, or an inference provider serving open models) is the fastest start. You pay per token, there is nothing to operate, and you get the strongest frontier models. The trade-offs are that your prompts and tool outputs leave your control, you share rate limits, and cost scales linearly with every token your agents read. Agents read a lot: every step resends the system prompt, tool definitions and the growing history.
Your own GPU running an open model behind an OpenAI-compatible server (vLLM is the usual choice) flips those trade-offs. Cost is per hour, not per token, so a busy GPU gets cheaper per task the more you use it. Prompts stay on your machine. You can fine-tune the model on your own traces and serve LoRA adapters per agent role. The catch is that you pay for idle hours, and the best open models still trail the best closed ones on the hardest reasoning tasks.
Most production teams end up with both. The routine 80% of steps (classify, extract, summarise, call a tool, write a short reply) go to a private open model; the hard 20% escalate to a frontier API. Because both speak the same OpenAI-style API, the switch is a base URL and a model name.
What GPU does a self-hosted agent model need?
Agent models need two things from a GPU: enough VRAM for the weights plus a large KV cache (agents carry long contexts), and enough memory bandwidth to decode quickly. The table uses the rule of thumb weights ≈ parameters × bytes per parameter, with 10–20% headroom.
| Model | Precision | Weights (approx.) | Smallest GPU that fits | Price |
|---|---|---|---|---|
| Qwen3 8B | BF16 | 8 × 2 = 16 GB | RTX 4090 (24 GB) | $1.59/hr |
| gpt-oss 20B | MXFP4 (native) | Runs in 16 GB (published) | RTX 4090 (24 GB) | $1.59/hr |
| Qwen3 32B AWQ | 4-bit | 32 × 0.55 ≈ 18 GB | L40S (48 GB) | $1.89/hr |
| Llama 3.3 70B FP8 | FP8 | 70 × 1 = 70 GB | H100 (80 GB) | $4.99/hr |
| gpt-oss 120B | MXFP4 (native) | Fits one 80 GB GPU (published) | H100 (80 GB) | $4.99/hr |
| Qwen3 235B-A22B FP8 | FP8 | 235 × 1 = 235 GB | B300 (288 GB) | $18.09/hr |
For most agent work a 32B-class model with reliable tool calling is the sweet spot: it fits a single L40S at 4-bit with room for KV cache, and it handles structured tool calls well. Move up to 70B–120B on an H100 or RTX PRO 6000 when the agent must plan over many steps, or when quality on your evaluation set says so.
Serving one yourself looks like this (vLLM 0.8 or later; flags change between versions, so check vllm serve --help):
pip install vllm
vllm serve Qwen/Qwen3-32B-AWQ \
--max-model-len 32768 \
--enable-auto-tool-choice \
--tool-call-parser hermes \
--enable-prefix-caching \
--api-key "$VLLM_API_KEY"Prefix caching matters more for agents than for chat: each step resends the same system prompt and history, and the cache means the GPU only processes the new tokens. Your agent code then changes one line:
import os
from openai import OpenAI
client = OpenAI(
base_url=os.environ["LLM_BASE_URL"], # e.g. https://your-endpoint/v1
api_key=os.environ["LLM_API_KEY"],
)
resp = client.chat.completions.create(
model=os.environ["LLM_MODEL"],
messages=[{"role": "user", "content": "List three risks of letting an agent run shell commands."}],
)
print(resp.choices[0].message.content)On Wandering Giants Compute the API option does the serving step for you: pick a GPU and a one-click model, and you get an OpenAI-compatible vLLM endpoint with your own key. The GPU vs CPU guide for agents covers which other agent components, such as embeddings, speech and vision, are worth putting on the same card.
Layer 2: where do agents run tools and code?
Agents run tools in a sandbox: an isolated environment with its own filesystem, process space and network rules, so that a bad command, a malicious package or a prompt-injected instruction cannot touch the host or other tenants. The isolation level you need depends on who writes the code the agent runs. If it is your code with model-chosen arguments, a container may do. If the model writes and executes arbitrary code, assume it is hostile.
| Isolation | How it works | Start time | Strength | Notes |
|---|---|---|---|---|
| Plain process | Subprocess on the host | Milliseconds | Weak | Only for trusted, fixed tools |
| Container (Docker) | Namespaces and cgroups on a shared kernel | Under a second to a few seconds | Moderate | Harden it: no root, no caps, no network by default |
| gVisor | User-space kernel intercepts system calls | About a container's | Strong | Drop-in runsc runtime for Docker; some syscall overhead |
| Firecracker microVM | Lightweight KVM virtual machine per sandbox | As little as 125 ms (published) | Strong, hardware-backed | Powers AWS Lambda; needs KVM on the host |
| Whole VM or machine | One full computer per agent | Minutes | Strongest | Best for long-lived agents with real toolchains |
You can build this yourself with Docker plus gVisor or Firecracker, or rent it. E2B runs open-source sandboxes on Firecracker microVMs with Python and JavaScript SDKs aimed squarely at agents. Daytona offers fast-starting sandboxes with an SDK and an open-source core. Modal Sandboxes run on Modal's gVisor-based container platform and suit teams already using Modal. All three bill by usage and remove a real operational burden; their limits are session length, the base images you can use, and the fact that your code and data run on their infrastructure.
Wandering Giants does not sell sandboxes as a service. What a Root machine gives you is different: a whole computer an agent can own, with SSH, a persistent disk, Ubuntu, CUDA and whatever tools you install. That is the right shape for a long-running agent that builds up a working environment, or for a coding agent that needs a GPU to run what it writes. The guides on why agents need their own computers and on what an agent sandbox is and how to choose one go deeper.
Layer 3: should agent environments be persistent or ephemeral?
Ephemeral environments are created for one task and destroyed after it; persistent ones survive between tasks. Default to ephemeral sandboxes with persistent state stored outside them. It gives you clean, reproducible runs and a small blast radius, while the things worth keeping (files, memory, results) live in a database or object store.
Persistence earns its cost when setup is expensive: a coding agent that has cloned a 2 GB repository, installed dependencies and warmed a build cache, or a research agent that has downloaded a dataset. Recreating that every task wastes minutes. The compromise most teams reach is a snapshot or a paused machine: keep the disk, stop paying for compute. On Wandering Giants a paused machine pays only for its disk, about 3¢ an hour per 50 GB.
There are four kinds of agent state, and they belong in different places:
- Conversation and task history: a database row per step, keyed by task ID.
- Long-term memory: a database plus a vector index for retrieval.
- Working files: the sandbox filesystem during the task, copied to object storage at the end.
- Installed environment: a container image or a persisted disk.
The full trade-off, with cost tables, is in persistent vs ephemeral environments for agents.
Layer 4: how are agent tasks queued and orchestrated?
Agent tasks should run as background jobs, not inside a web request. A single task can take minutes, make dozens of model calls and fail halfway through, so it needs a queue, a pool of workers, timeouts, retries and a record of every step.
A minimal production shape is: an API that accepts a task and returns a task ID, a Redis-backed queue, N worker processes that each run one agent loop at a time, and Postgres for step history. Here is the enqueue side with RQ:
from redis import Redis
from rq import Queue
q = Queue("agent-tasks", connection=Redis.from_url("redis://localhost:6379/0"))
job = q.enqueue("agent.run_agent", "Summarise this week's support tickets", job_timeout=900)
print(job.id)For long tasks with human approval steps, or tasks that must survive a worker crash mid-step, a durable workflow engine such as Temporal records each step and replays from the last one. It is more to run, and worth it once tasks take hours or touch money.
Orchestration is also where you enforce budgets: a maximum number of steps, a maximum token count, a wall-clock limit and a cost ceiling per task. Agents that loop are the most common production failure, and a hard cap is the only reliable fix. The step-by-step tutorial on running autonomous agents in the cloud builds this end to end, and multi-agent infrastructure covers orchestrators that coordinate several agents.
Layer 5: how do agents use a web browser?
Agents browse with a real headless browser, usually Chromium driven by Playwright, either self-hosted or from a hosted browser service. The agent either reads extracted page text and calls actions such as click and type, or works from screenshots with a vision model.
Browsers are the hungriest part of the CPU side. A headless Chromium instance commonly uses several hundred MB to over 1 GB of RAM with a heavy site open, so a host with 32 GB of RAM runs tens of concurrent browsers, not hundreds. Plan memory before CPU.
from playwright.sync_api import sync_playwright
def read_page(url: str) -> str:
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto(url, timeout=30_000)
text = page.inner_text("body")
browser.close()
return text[:20_000]Two rules keep browsing safe. First, treat every page as untrusted input: pages can carry instructions aimed at your agent (prompt injection), so the browser should hold no credentials the task did not grant. Second, run the browser inside the same sandbox boundary as other tools, with an egress policy, not on the orchestrator host. Hosted browser services such as Browserbase handle scaling, fingerprinting and session recording for you, at a per-session or per-minute price.
Layer 6: how do you handle secrets and permissions for agents?
Give agents capabilities, not credentials. The agent should be able to call "create invoice draft" or "read the CRM record for this customer", while the actual API key lives in a tool service the agent cannot read. If a prompt injection convinces the agent to print its environment, there is nothing useful in it.
The practical controls:
- A tool proxy. Tools run in a service that holds the keys and checks each call against the task's permissions. The sandbox gets no secrets in its environment.
- Scoped, short-lived tokens. Where an agent must hold a credential (for example a Git token in a coding sandbox), issue one per task, scoped to one repository, expiring in an hour.
- Egress allowlists. Sandboxes reach only the hosts the task needs. Default to no network.
- Human approval for irreversible actions. Sending email, moving money, deleting data and publishing pause the task until a person approves.
- Per-task audit logs that record which tool was called with which arguments, by which task, on whose behalf.
The Model Context Protocol (MCP) has become a common way to expose tools to agents. It standardises the interface; it does not decide who may call what. You still need the proxy and the permission check behind it.
Layer 7: how do you observe and debug agents?
You debug agents by tracing them: every model call, tool call, input, output, token count, latency and cost, grouped under one task ID. Without traces, "the agent did something odd on Tuesday" is unanswerable.
At minimum, log one structured record per step:
{"task_id": "t_8f2c", "step": 7, "type": "tool_call", "tool": "run_shell", "args": {"command": "pytest -q"}, "exit_code": 1, "duration_ms": 4210, "prompt_tokens": 11842, "completion_tokens": 212}OpenTelemetry gives you the trace and span model; Langfuse, LangSmith and Arize Phoenix are popular tools built for LLM traces specifically, and Langfuse can be self-hosted. Whatever you choose, track four numbers per task type: success rate, steps, tokens and cost per task. They show whether a prompt change or model swap helped, and feed the evaluation set that decides whether a cheaper model is good enough.
Does an AI agent need a GPU?
An agent only needs a GPU for model inference, and only when you run the model yourself. The orchestrator, sandboxes, browsers, queues, databases and tracing are CPU workloads. A team calling a hosted API can run thousands of agent tasks a day without owning or renting a single GPU.
A GPU becomes worth it when one of these is true: you need prompts and data to stay on infrastructure you control; your token volume makes per-hour pricing cheaper than per-token pricing; you want a fine-tuned or specialist model; or the agent's own work needs a GPU (training a model, rendering, running speech or image models). The GPU vs CPU breakdown for agents goes component by component.
How much does an AI agent task cost?
Cost per task = model cost + sandbox cost + browser cost + storage, and the model term usually dominates. The model term is driven by input tokens, because agents resend their context on every step. Here is a worked example you can adapt.
The task profile (an assumption, typical of a tool-using support or research agent): 12 model calls; the context grows from about 6,000 tokens (system prompt, tool definitions, task) to about 12,000; average prompt 9,000 tokens; 300 output tokens per call.
| Quantity | Formula | Result |
|---|---|---|
| Input tokens per task | 12 calls × 9,000 | 108,000 |
| Output tokens per task | 12 × 300 | 3,600 |
| Hosted API cost per task | 0.108 M × $0.40 + 0.0036 M × $1.60 | ≈ $0.049 |
| Hosted cost per 1,000 tasks | 1,000 × $0.049 | ≈ $49 |
The $0.40 and $1.60 per million tokens are an illustrative mid-tier price, not a quote; frontier models cost several times more, small models less, and many providers discount cached input. Substitute your provider's numbers.
Now the same task on your own L40S running Qwen3 32B AWQ with prefix caching. Because history is cached, the GPU mostly processes new tokens: call it about 20,000 tokens of fresh prefill per task (the final context plus some cache misses) and 3,600 tokens of decode.
| Quantity | Assumption (estimate) | GPU-seconds per task |
|---|---|---|
| Prefill | 20,000 tokens at 1,500–2,500 tokens/s | 8–13 s |
| Decode share | 3,600 tokens at 250–400 tokens/s aggregate (batched) | 9–14 s |
| Total | ≈ 17–27 s | |
| Tasks per GPU-hour | 3,600 ÷ 17–27 | ≈ 130–210 |
| GPU time per 1,000 tasks | 1,000 ÷ 130–210 | ≈ 4.8–7.7 GPU-hours |
| Cost per 1,000 tasks on Wandering Giants | 4.8–7.7 GPU-hours at $1.89/hr | $9.07–$14.55 |
The throughput figures are estimates from the card's compute and bandwidth and typical vLLM batching, not measurements; they swing with prompt length and concurrency, so check them on your own workload. The point of the table is the shape of the maths: on a busy GPU, the per-task model cost is a handful of GPU-seconds.
The catch is utilisation. A GPU that is on all day costs 24 × the hourly price whether it runs 100 tasks or 4,000. Break-even against the hosted example is 24 × hourly price ÷ $0.049 ≈ 490 tasks a day for every dollar of hourly GPU price. Below that, the hosted API is cheaper unless privacy or control is the reason you are self-hosting. Above it, your own GPU wins, and by a growing margin. Per-minute billing helps at the low end: run the GPU during working hours and stop it overnight, and the break-even falls in proportion.
Sandbox cost is usually small next to the model: a task that holds a 1 vCPU, 2 GB sandbox for four minutes uses about 0.07 vCPU-hours, which is fractions of a cent on most clouds and sandbox services. Browsers cost more because of memory, and hosted browser sessions are priced per minute or per session.
How do you scale agents from one user to thousands?
You scale agents by scaling three things separately: worker concurrency (how many agent loops run at once), model throughput (tokens per second across all of them) and sandbox capacity (how many isolated environments exist at once). They hit limits at different times.
Little's law gives the concurrency you need: concurrent tasks = tasks per second × seconds per task. At 750 tasks in a peak hour and four minutes per task, that is 750 ÷ 3,600 × 240 = 50 tasks in flight. Fifty agent loops are cheap on CPU; fifty long contexts in a model's KV cache need serious VRAM. For a 32B model with 0.25 MB of KV cache per token, 50 sequences of 10,000 tokens need about 125 GB: far more than an L40S has, and more than an H200 has free after 4-bit weights, unless you store the KV cache in FP8, which halves it to about 62 GB. Scaling agents from one user to thousands works through this, including why you add GPUs in steps rather than relying on autoscaling.
Wandering Giants does not offer serverless autoscaling or scale-to-zero endpoints. Providers such as Modal, RunPod Serverless and Baseten do, and they suit spiky traffic. A fixed GPU you start and stop by the minute suits steady agent traffic, where an always-warm model with a hot prefix cache matters more than scaling to zero.
Are coding agents different?
Coding agents are the heaviest agent workload: long sessions, very large contexts (whole files and test output), real toolchains, and often a need for persistent workspaces. A single coding task can read over a million input tokens across 30–60 steps, which makes token price and prefix caching the dominant cost decisions.
They also need the richest sandbox: a full Linux environment with Git, language toolchains, package managers and sometimes a GPU to run the code they write (a training script, a CUDA kernel, a model evaluation). That is where a whole machine beats a short-lived sandbox. Running coding agents in the cloud covers the architecture and the maths.
What does a complete agent stack look like?
Three reference architectures cover most teams. Start at the smallest one that meets your privacy and volume needs; each upgrade is additive.
| Stage | Model | Sandbox | Orchestration | State | Observability |
|---|---|---|---|---|---|
| Prototype | Hosted API | Hardened Docker on your laptop or a VPS | In-process loop | SQLite or files | Printed JSON logs |
| Team product | Hosted API + one private GPU endpoint for routine steps | Sandbox service or Docker + gVisor | Redis queue + workers | Postgres + object storage | Langfuse or OpenTelemetry |
| Private platform | Private GPU endpoints, frontier API as fallback | Self-hosted gVisor or Firecracker fleet, Root machines for long-lived agents | Durable workflows | Postgres + vector index + object storage | Self-hosted tracing, cost dashboards |
The last column is where many teams under-invest and regret it. The tutorial on building a private AI agent platform assembles the third row with docker-compose and a rented GPU.
For a side-by-side of where to rent the GPU layer, see the best GPU cloud providers for AI agent infrastructure.
Build it yourself or get help?
Build it yourself if you have an engineer who has run queues, containers and Postgres in production: none of the layers is exotic, and the open-source pieces are mature. Get help when the agent touches customers, money or regulated data, because the hard decisions are about permissions, failure modes and evaluation rather than code.
Wandering Giants is an agentic venture studio: as well as renting GPUs, it designs and builds agent systems for businesses, on whichever models and infrastructure suit the job. If you would rather start from a working system than a blank repository, see Wandering Giants consulting.
When does renting from Wandering Giants fit?
Wandering Giants Compute fits the model layer and long-lived agent machines. Use the API option when you want a private open model that many agents share through one OpenAI-compatible endpoint, with prompts that never go to a shared AI API. Use Root when an agent, or a fleet of agent workers, needs a whole computer with SSH, a persistent disk and a GPU. Billing is by the minute from prepaid credit, so a GPU you stop overnight costs nothing but disk, and it can never bill beyond what you put in.
It is not the right fit if you need serverless scale-to-zero, a managed sandbox fleet, multi-node clusters or a compliance certification; other providers offer those, and the guides above name them. For a private agent model on one card from 24 GB to 288 GB, see the GPUs and prices.
Frequently asked questions
What is the difference between an AI agent and AI agent infrastructure?
The agent is the loop: a model deciding which tool to call next until a task is done. The infrastructure is what that loop runs on: the model server, the sandbox that executes tools, the storage, the queue, the browser, the secrets store and the tracing. You can swap agent frameworks without changing most of the infrastructure.
Do AI agents need GPUs?
Only the model needs a GPU, and only if you host it yourself. Orchestration, tool execution, browsers, queues and databases all run on ordinary CPUs. If you call a hosted model API, your agent stack may need no GPU at all.
What is an agent sandbox?
A sandbox is an isolated environment where an agent runs code, shell commands and other tools without being able to damage the host or reach things it should not. Common choices are hardened containers, gVisor, Firecracker microVMs and dedicated machines, either self-hosted or from services such as E2B, Daytona and Modal.
How much does it cost to run an AI agent task?
Multiply input and output tokens by your model price, then add sandbox and browser time. A typical 12-step task uses roughly 108,000 input and 3,600 output tokens, which is a few cents on a hosted API, or a few GPU-seconds on your own busy GPU. Idle GPU hours change that picture quickly.
Should I self-host the model my agents use?
Self-host when you need privacy, predictable cost at high volume, a fine-tuned model, or freedom from rate limits. Use a hosted API when volume is low or spiky, or when you need the strongest frontier model. Many teams run both behind one OpenAI-compatible interface.
Which framework should I use to build agents?
The infrastructure in this guide works with any framework, including the OpenAI Agents SDK, LangGraph, PydanticAI or a 100-line loop of your own. Pick the framework for its programming model; the hard production problems are isolation, state, retries, cost control and tracing.
Rent the GPU for this, by the minute.
Give your agents a private model: launch an L40S or H100 with an OpenAI-compatible API in minutes, billed by the minute from prepaid credit.
Prepaid credit, billed by the minute, stops itself when credit runs out. Prices in £, $, €, ¥, CA$, A$, CHF and S$; UK prices include VAT.
Keep reading
- ComparisonBest GPU Cloud Providers for AI Agent Infrastructure
- GuideWhy AI Agents Need Their Own Computers and Execution Environments
- GuideWhat Is a Sandbox Environment for AI Agents?
- TutorialHow to Run Autonomous AI Agents on Cloud Infrastructure
- TutorialHow to Build a Private AI Agent Infrastructure Platform
- Complete guideWhat Is GPU Cloud Computing? The Complete Guide
About this article. Written by the Wandering Giants Compute team, the people who run Wandering Giants Compute. Hardware figures are the manufacturers’ published specifications. Speeds and costs marked as estimates are worked out from those specifications and our current prices, with the method shown; they are not measured benchmarks. Wandering Giants prices are taken live from our price list each time this page is built.
Last reviewed 25 November 2026.