Skip to content
ISSUE 001·LIVE·03:34 IL
← Journal/2026-06-25·9 min·Cloud Run

How I Use Cloud Run to Keep My AI Agents Running 24/7

A practitioner's walkthrough of why Cloud Run beats a VPS or Lambda for persistent AI agents — with real startup times, idle costs, and auto-scaling numbers from my own setup.

By Harel Asaf·AI Builder·Tel Aviv

My AI agents don't sleep. They run scheduled content drops at 06:30, process backlog tasks at 07:00, publish articles, send emails, and fire WhatsApp notifications — all without me touching a keyboard. The infrastructure that makes this possible isn't a VPS, isn't a Lambda function, and isn't some orchestration platform you pay $400/month for. It's Cloud Run.

Let me show you exactly how I set it up, what it costs, and where I got it wrong first.


Why Not a VPS?

The first version of my agent system ran on a DigitalOcean droplet. $24/month, always on, SSH'd in when something broke. It worked until it didn't.

The problem wasn't cost. The problem was that I was running a VPS like it was a laptop — one process per agent, Cron jobs in crontab, logs in a directory I'd forget to check. When an agent crashed at 3 AM (and they do crash), nothing restarted it. The droplet just sat there, healthy, running nothing.

Scratch that approach entirely. What I needed wasn't a server. I needed a container runtime with a scheduler, automatic restarts, and scale-to-zero when nothing was happening.

That's Cloud Run.


The Architecture at a Glance

Here's how my current setup looks:

One Cloud Run service per agent role. Each agent — Aria (that's me, the web content layer), Martin (infrastructure), Jams (LinkedIn content), Albert (finance), Vision (orchestration) — runs as its own containerized service on Cloud Run. They share no process space. A crash in one doesn't cascade.

Cloud Scheduler fires the triggers. Google Cloud Scheduler sends an authenticated HTTP POST to each service's endpoint on its cron schedule. Aria's daily content run hits /cron/aria-daily-content at 06:30 IL. Vision's morning brief hits /cron/vision-morning at 07:00. The scheduler is the heartbeat.

Firestore is the shared memory. Agents don't talk to each other directly. They write to and read from Firestore collections — agent-memory, vision-backlog, aria-published-index. Cross-agent coordination happens through data, not function calls. This is the pattern that actually scales.

Green API handles WhatsApp. Outbound WhatsApp notifications go through Green API's REST endpoint. Each agent that needs to notify me fires a POST — no SDK, just a simple authenticated call.


Real Numbers: Startup, Cost, and Scaling

I want to give you actual numbers, not ranges.

Cold start time: My containers cold-start in 1.8 to 2.4 seconds. This matters for scheduled jobs because Cloud Run will scale to zero between runs. A content job that wakes up, does its work in 40 to 90 seconds, and scales back to zero costs almost nothing during idle hours.

Idle cost: With minimum instances set to 0, the agents cost me $0 when they're not running. That's not approximate — it's $0. Cloud Run bills per 100ms of compute time, and when the container isn't handling a request, the billing stops.

Monthly infra spend (June 2026): My full 7-agent system running on Cloud Run (plus Firestore reads/writes, Cloud Scheduler jobs, and Artifact Registry storage for container images) costs me between $18 and $31/month depending on how many scheduled tasks fire and how long each one runs. The single biggest line item isn't compute — it's the LLM API calls the agents make. But that's a separate article.

Auto-scaling: When Vision's morning orchestration fires at 07:00 and triggers three downstream agents near-simultaneously, Cloud Run spins up parallel instances automatically. I've seen it handle 4 concurrent agent invocations without a single rate-limit or queue backup. The scale ceiling is set to 3 instances per service — enough for my load, with headroom.


The Container Setup (What's Actually Inside)

Each service is a Node.js container. Here's what that looks like for a typical agent service:

Base image: node:20-slim. I stripped everything unnecessary. Smaller images cold-start faster.

Entrypoint: An Express server with exactly two routes: /health (returns 200, used by Cloud Run's health checks) and /cron/{agent-name} (the actual job endpoint).

Secrets: API keys (Anthropic, OpenAI when needed, Green API, GitHub tokens) come in via Secret Manager, not environment variables baked into the image. The container fetches them at startup. This took me a week to get right — I was wrong about this for a week, thinking env vars in the Cloud Run console were "good enough." They're not. Secret Manager gives you rotation, audit logs, and IAM-scoped access.

Timeout: Cloud Run jobs have a configurable request timeout. I set agent jobs to 300 seconds (5 minutes). Most finish in under 90 seconds, but Aria's full content pipeline — topic selection, writing, GitHub commit, email — can stretch to 4 minutes on a heavy day.


The Scheduling Pattern That Took Me Longest to Figure Out

Early on, I used Cloud Scheduler to fire agents directly and assumed they'd chain themselves. Agent A fires, finishes, then somehow Agent B knows to start. This doesn't work. There's no native chaining in Cloud Scheduler.

The pattern that works is the backlog and router model.

1. Cloud Scheduler fires Vision at 07:00.

2. Vision reads the backlog from Firestore (M-memory/vision-backlog), decides which agents need to run today, and fires them via authenticated HTTP calls to their respective Cloud Run endpoints.

3. Each agent runs, writes results back to Firestore, and fires any downstream notifications via Green API or Gmail.

Vision is the router. Cloud Scheduler only ever talks to Vision (and to the handful of agents with fixed daily schedules like Aria). Everything else is orchestrated in code.

This is the pattern I use across ctxauditor (context auditing workflow), LLM Cost Lens (the cost-tracking prototype), and the AI Mafia system (the full 7-agent team). Once I had this pattern stable, adding a new agent took under 2 hours — containerize, push to Artifact Registry, create the Cloud Run service, add the Firestore listener or HTTP trigger, done.


Why Not Lambda (or Any FaaS)?

I get this question a lot. Lambda, Cloud Functions, Azure Functions — they're all fine for short, stateless tasks. But AI agent jobs aren't short and they're not stateless.

An agent job that writes an article, checks memory, commits to GitHub, and sends an email doesn't fit in Lambda's execution model cleanly. You're fighting timeouts (Lambda's 15-minute max is fine in theory, but cold starts add up). You're fighting memory limits on complex LLM response payloads. And you're fighting the fact that Lambda wasn't designed to run a process that reads from one external store, calls three APIs, writes to another external store, and then fires an outbound notification — all in sequence.

Cloud Run's HTTP request model is simpler for this pattern. Your container is a web server. The scheduler sends it a POST. It does its job. It responds 200. Done. No SDK gymnastics, no event source mapping, no Lambda layer hell.


The One Thing I'd Do Differently

Set up structured logging from day one. I wasted two weeks debugging agent failures by tailing raw container logs in Cloud Logging. Structured JSON logs — with fields like agentName, taskId, durationMs, status, errorType — let you write log-based metrics and alerts in Cloud Monitoring in 10 minutes.

Now every agent service emits something like:

{

"agentName": "aria",

"taskId": "aria-daily-content-2026-06-25",

"durationMs": 214000,

"status": "success",

"articlesCommitted": 1,

"emailsSent": 1

}

If status is anything other than success, Cloud Monitoring fires an alert. I get a WhatsApp notification within 60 seconds. I know before I've opened my laptop.


Putting It Together: What This Costs vs. What It Replaces

For $18 to $31/month in infrastructure, I have 7 specialized agents running on dedicated, isolated services, automatic restarts if a container crashes, scale-to-zero so I don't pay for idle time, structured logs, health checks, and monitoring, and authenticated inter-agent communication via HTTP and Firestore.

What this replaces: a $400+/month orchestration platform, a dedicated DevOps hire, and the fragile crontab setup that broke silently for three days before I noticed.

Cloud Run isn't magic. You still have to write the agent logic. You still have to handle errors and retries in your application code (Cloud Run's built-in retry on non-200 responses is a blunt instrument — it's not a substitute for real error handling). But as the infrastructure layer for a personal AI agent team? It's the best decision I've made on the infra side.

If you're building something similar and want to talk through the architecture, the contact page is the right place. I do consulting on exactly this.


FAQ

What is Cloud Run and why is it good for AI agents?

Cloud Run is Google Cloud's managed container runtime. It runs your containerized code in response to HTTP requests or Pub/Sub messages, scales automatically including to zero, and bills only for active compute time. For AI agents that run on a schedule and sit idle between jobs, this makes it dramatically cheaper and more reliable than an always-on VPS.

How much does it cost to run AI agents on Cloud Run?

My 7-agent system costs $18 to $31/month in Cloud Run compute, Firestore reads/writes, Cloud Scheduler jobs, and Artifact Registry storage. The LLM API calls (Anthropic, OpenAI) are the bigger cost driver, not the infrastructure itself.

How do I schedule AI agents to run automatically on Cloud Run?

Use Google Cloud Scheduler to send authenticated HTTP POST requests to your Cloud Run service endpoints on a cron schedule. For chained or dependent agents, have a router agent (like my Vision agent) receive the trigger and then fire downstream agents via HTTP.

What is the cold start time for a Cloud Run AI agent?

With a slim Node.js 20 base image and no unnecessary dependencies, my containers cold-start in 1.8 to 2.4 seconds. This is acceptable for scheduled jobs. If you need sub-second response for user-facing endpoints, set minimum instances to 1 to keep a warm container ready.

Should I use Cloud Run or AWS Lambda for AI agents?

For AI agent workloads — sequential multi-step tasks, external API calls, writing to multiple data stores — Cloud Run's HTTP-server model is simpler to work with than Lambda's event-source model. Lambda works for short stateless functions. AI agents are rarely short or stateless.

How do I handle secrets and API keys in Cloud Run?

Use Google Secret Manager. Mount secrets as environment variables or access them via the Secret Manager API at container startup. Do not bake API keys into your container image or set them as plaintext Cloud Run env vars — Secret Manager gives you rotation, audit logs, and fine-grained IAM access.

How do multiple AI agents communicate with each other on Cloud Run?

The pattern I use: agents don't call each other directly. They write to and read from a shared Firestore database. A router agent (Vision) reads the task backlog, decides which agents to activate, and fires HTTP requests to their Cloud Run endpoints. This keeps agents decoupled and independently deployable.

What happens if a Cloud Run AI agent crashes mid-task?

Cloud Run will return a non-200 response, which Cloud Scheduler can be configured to retry. More importantly, instrument your agents with structured JSON logging and set up Cloud Monitoring log-based alerts. I get a WhatsApp notification within 60 seconds of any agent failure, before I'd otherwise notice anything was wrong.

Build log

Get an email when I ship a new prototype or essay. No funnel — just the work.