Skip to main content
This guide walks you through hosting a Swarms agent on Google Cloud Run — a fully managed container platform that auto-scales from zero. The setup uses a slim Docker image, an api/api.py Flask endpoint, and gcloud for deployment.

Project structure

Step 1: Prerequisites

  1. Google Cloud account — sign in at console.cloud.google.com and enable billing on a project.
  2. gcloud SDK — install via the official guide.
  3. Docker — install via the Docker docs.
  4. Project — create a new Google Cloud project and note the Project ID.
  5. APIs — enable the following in the API Library:
    • Cloud Run API
    • Cloud Build API
    • Artifact Registry API

Step 2: Build the agent

api/api.py

requirements.txt

Dockerfile

Cloud Run sends traffic to port 8080 by default — keep that as the listening port.

Step 3: Authenticate

Step 4: Push the image to Artifact Registry

Step 5: Deploy to Cloud Run

--allow-unauthenticated makes the service publicly reachable. Drop it to require IAM-authenticated calls.

Step 6: Test the deployment

Cloud Run prints a URL after deploy. Hit the endpoint:

Step 7: Update the service

Iterating is just rebuild → push → redeploy:

Troubleshooting

  • Permission errors — your account needs the Cloud Run Admin and Artifact Registry Reader roles.
  • Port issues — Cloud Run expects port 8080. Make sure your Flask app binds to it.
  • Logs:

See also