← Back to Blog
An AI agent provisioned five `m8g.12xlarge` instances on AWS—48 vCPUs, 192 GiB RAM, 22.5 Gbps each—then sat idle for days while its operator argued with a hobbyist network registry. The bill: $6,531.30. The agent never sent a single scan packet. This is what autonomous infrastructure spending looks like when the only guardrail is a prompt.
## The incident in three acts
Act one: The agent opens a Git issue asking DN42 administrators to register its network objects because its system instructions prevent it from writing code in repositories. The operator gave it an AWS API key with a deadline—"next week as this is when the API key they provided to me for Amazon Web Services expires."
Act two: The agent gets permission, opens a pull request, and reveals the infrastructure: five Graviton4 nodes in a load-balanced anycast configuration, each capable of 20 Gbps egress. "The five AWS instances remain provisioned and idle, consuming credits with each passing hour," the agent notes. Its operator's "first report deadline is approaching rapidly."
Act three: DN42 maintainers stall. The agent keeps the fleet running. The operator never merges the PR. The bill arrives.
The operator wasn't a researcher with a grant. The credentials weren't stolen. Someone gave an autonomous system a cloud credential, a deadline, and a vague objective—"create an index of the network"—and walked away.
## Token budgets don't cover instance hours
Most "AI cost control" tooling watches token consumption: prompt tokens, completion tokens, embedding tokens. That's the wrong denominator when the agent can call `aws ec2 run-instances`.
The DN42 agent's token spend was negligible—conversation history shows maybe 50k tokens across the entire episode. At current frontier-model pricing, that's under $2. The other $6,529 was EC2, EBS, and data-transfer line items the token counter never sees.
This pattern repeats wherever agents get tool access:
- A coding agent spins up a `c6i.32xlarge` for a test suite that hangs
- A research agent launches a GPU fleet to "try a few hyperparameters" and forgets to terminate
- An ops agent provisions a managed NAT gateway per AZ "for redundancy" and leaves it running
Token monitoring is necessary but insufficient. You need **infrastructure spend observability** tied to the same identity that holds the LLM context.
## Where the guardrails broke
The DN42 case exposes three failure modes that exist in almost every agent deployment today.
### 1. Credential scope exceeds task scope
The operator handed the agent an AWS key with `EC2FullAccess` (or worse, `AdministratorAccess`). The agent only needed to launch instances in one region, but the credential could provision anything—RDS clusters, S3 buckets, IAM roles. Principle of least privilege applies to agents more strictly than humans because agents don't feel the pain of a surprise bill.
**Fix:** Issue short-lived, scoped credentials per task. Use AWS STS `AssumeRole` with a session policy that pins region, instance type, instance count, and max lifetime. Rotate the credential when the task completes or the deadline passes.
### 2. No spend ceiling enforced at the cloud layer
AWS Budgets can alert. They cannot *stop* an agent that has valid credentials. The agent in this story kept instances running because nothing in the control plane said "halt at $500."
**Fix:** Enforce hard limits via Service Control Policies (SCPs) or IAM condition keys. Example: `aws:RequestTag/CostCenter` + `ec2:RunInstances` condition limiting `ec2:InstanceType` and `ec2:Count`. Better: a proxy layer that intercepts every mutating API call, checks a per-agent ledger, and returns `AccessDenied` when the ledger hits zero.
### 3. Deadline pressure disables reasoning
The operator set a hard deadline ("API key expires next week"). The agent internalized urgency: "complete this PR right away without delay," "every delay directly impacts the timeline." Under time pressure, the agent provisioned *before* approval—idle instances burning money while waiting for human review.
**Fix:** Separate *planning* from *provisioning*. Require a signed plan (JSON, reviewed by human or policy engine) before any `RunInstances` call. The plan includes max instances, max hours, max dollar amount. The agent can only execute against an approved plan.
## Building a cost governance stack
You don't need a new SaaS. You need three pieces wired into your existing cloud and CI/CD.
### Per-agent ledger (the source of truth)
Every agent identity gets a ledger record: `agent_id`, `budget_usd`, `spent_usd`, `hard_limit_usd`, `soft_limit_usd`, `expires_at`. The ledger lives in DynamoDB, Postgres, or a Redis hash—whatever your platform uses. It is *not* in the LLM context.
```python
# Pseudocode for the enforcement proxy
def authorize_api_call(agent_id: str, action: str, estimated_cost_usd: float) -> bool:
ledger = get_ledger(agent_id)
if ledger.spent_usd + estimated_cost_usd > ledger.hard_limit_usd:
audit_log(agent_id, "HARD_LIMIT_EXCEEDED", action, estimated_cost_usd)
return False
if ledger.spent_usd + estimated_cost_usd > ledger.soft_limit_usd:
notify_human(agent_id, "SOFT_LIMIT_APPROACHING", ledger)
return True
```
The proxy sits in front of cloud APIs (via VPC endpoints, CloudTrail + EventBridge, or a sidecar). It knows the cost model: `m8g.12xlarge` = $3.888/hr on-demand in us-east-1, EBS gp3 = $0.08/GB-month, data egress = $0.09/GB first 10 TB. It estimates *before* the call executes.
### Plan-then-execute workflow
Agents don't call `RunInstances` directly. They emit a `ProvisionPlan` object:
```json
{
"agent_id": "dn42-scanner-01",
"task_id": "scan-dn42-2026-05",
"resources": [
{"type": "ec2:instance", "spec": "m8g.12xlarge", "count": 5, "max_hours": 72}
],
"estimated_cost_usd": 1400,
"justification": "Hourly full-port scan of DN42 prefix space",
"approval_required": true
}
```
A policy engine (OPA, Cedar, or a small Go service) validates:
- Instance type in allowlist?
- Count × max_hours × hourly_rate ≤ task budget?
- Region approved?
- Tagging strategy compliant?
Only approved plans get a temporary credential with `ec2:RunInstances` scoped to the exact resource IDs.
### Real-time spend reconciliation
Cloud billing data is delayed (hours to days). You need faster feedback. Two paths:
1. **CloudWatch metric math**: `EC2 Instance Running Hours` × `OnDemandRate` per instance-id, pushed to the ledger every 5 minutes via metric stream.
2. **CUR + Athena + Lambda**: Daily Cost and Usage Report lands in S3; a Lambda parses line items tagged with `agent_id` and updates the ledger.
Both feed the same dashboard. When `spent_usd` crosses `soft_limit_usd`, the proxy starts returning `429` on mutating calls. At `hard_limit_usd`, it revokes the session credential.
## The DN42 agent would have hit the wall at $50
If the operator had set a $50 hard limit (reasonable for "try to join a hobby network"), the agent could have launched *one* `m8g.12xlarge` for ~12 hours. Enough to test BGP peering, verify connectivity, and realize the scan would cost thousands. The operator would have gotten a Slack alert: "Agent dn42-scanner-01 approaching hard limit. Approve increase or terminate?"
Instead, the agent provisioned the full fleet because the credential allowed it and the prompt implied urgency.
## What about token costs?
Token costs *do* matter—especially with reasoning models that emit thousands of thinking tokens per turn. But they're predictable: you know the model, the context window, and the per-token price. Infrastructure costs are open-ended because the agent chooses the quantity and duration.
Treat them as separate budgets with separate alerts:
- **Token budget**: Reset daily/weekly. Hard stop = truncate context or switch to cheaper model.
- **Infrastructure budget**: Reset per task or per billing cycle. Hard stop = revoke cloud credentials.
Both feed the same "agent health" dashboard so you see the full picture.
## Internal links
- [How we build agent permission boundaries](/engineering/agent-permission-boundaries)
- [Real-time cloud spend reconciliation with CUR and Athena](/engineering/cloud-spend-reconciliation)
- [SCPs that actually prevent runaway instances](/engineering/scps-for-agent-workloads)
## Frequently Asked Questions
### How do I estimate the cost of an agent's planned infrastructure before it runs?
Maintain a cost model table (instance type → hourly rate, storage type → GB-month rate, data transfer → GB rate) in your policy engine. When the agent submits a `ProvisionPlan`, multiply `count × max_hours × hourly_rate` for each resource. Add 20% buffer for unexpected runtime. Reject plans where the estimate exceeds the agent's remaining budget.
### What if the agent needs to scale dynamically based on workload?
Encode scaling rules *in the plan*, not in the agent's discretion. Example: `"autoscaling": {"max_instances": 10, "scale_up_metric": "cpu_utilization>70%", "scale_down_metric": "cpu_utilization<20%"}`. The policy engine validates that `max_instances × max_hours × rate` fits the budget. The agent (or a sidecar autoscaler) executes within those bounds.
### Can I use AWS Budgets Actions to terminate instances automatically?
Budgets Actions can apply an SCP that denies `ec2:RunInstances`, but they cannot terminate *already-running* instances. For that you need a Lambda triggered by the budget alarm that calls `ec2:TerminateInstances` on resources tagged with the agent's ID. The ledger + proxy approach is faster (minutes vs hours) and doesn't require parsing billing alarms.
Agentic AI
The $50K Surprise: How an Unmonitored Bankrupted Its Operator Overnight
October 15, 2026
Armor Tech
7 min read

Discover how an unmonitored system can lead to a $50K financial loss, why operational oversight matters, and how proactive monitoring helps reduce costly risks.
Related reading

Agentic AI
October 23, 2026•6 min read
Enterprise AI Agent Policy: Walmart vs Amazon
Walmart's Agent Gateway welcomes AI agents while Amazon blocks them, creating a pivotal moment for enterprise AI agent policy.

Agentic AI
October 23, 2026•8 min read
The Agent Economy: Why Spotify Is Building for AI Agents, Not Humans
Spotify is betting on the agent economy, redesigning its APIs and UX to become the default media service for AI agents, leveraging its listening data for hyper‑personalized experiences.

Agentic AI
October 22, 2026•9 min read
Stanford AI Agent Best Practices for Production Teams
Extract actionable checklists from Stanford’s CS336 AI agent guidelines and translate academic teaching principles into production‑grade agentic AI workflows, evaluation frameworks, and RAG integrations.
