Skip to main content
Run Libretto workflows as Cloud Run Jobs, triggered from your API or a scheduler.
Cloud Run Jobs are GCP’s managed container runtime for one-shot tasks. Each invocation spins up a fresh container, runs your workflow to completion, and exits. That’s a good fit for browser automations that take minutes rather than seconds.

Prerequisites

  • A GCP project with billing enabled.
  • Artifact Registry, Cloud Run, Cloud Build, and Secret Manager APIs enabled.
  • A service account with access to the secrets your workflows need.
  • gcloud installed and authenticated locally.
1

Write a dispatcher entry point

A single image should be able to run any workflow in your package. The simplest way is a small src/main.ts that reads two env vars (which workflow to run, and its JSON input) then calls into the workflow directly:
Wire it up in package.json:
2

Write the Dockerfile

Start from the official Playwright image so Chromium and all its dependencies are already present. The rest installs pnpm, copies your source, and hands off to the dispatcher on start:
Add a .dockerignore at the repo root so local state doesn’t leak into the image:
3

Define the Cloud Run Job

Describe the job declaratively so you can version it alongside your code. The shape below matches what gcloud run jobs replace emits after you create a job through the console or CLI:
The serviceAccountName is what grants the job permission to read secrets, write to GCS, and so on. Scope it tightly.
4

Build and deploy via Cloud Build

Trigger a build and deploy:
5

Inject credentials at runtime

Never bake credentials into the image. Read them from Secret Manager inside your workflow dispatcher:
Grant the job’s service account roles/secretmanager.secretAccessor on each secret it needs:
6

Trigger the job

From your API (service-to-service), pass the workflow name and input as env var overrides so the dispatcher picks them up:
From the CLI for ad-hoc runs:
7

Observability

  • Logs: gcloud logs read browser-agent-job —region=us-central1
  • Execution history: gcloud run jobs executions list —job=browser-agent-job —region=us-central1
  • Session logs: upload .libretto/sessions/<name>/logs.jsonl to GCS at the end of each run if you want to keep them beyond the job’s lifetime.
Libretto writes detailed network, action, and snapshot logs under .libretto/sessions/<name>/. Pushing that directory to GCS on failure gives you a reproducible record for debugging. See debugging workflows for what to look at.