Skip to main content

Overview

Agent Browser can run in serverless environments by using lightweight Chromium builds and the programmatic API. The bundled Chromium (~684MB) is too large for most serverless platforms, so you’ll need to use optimized alternatives like @sparticuz/chromium (~50MB).

Quick Start

For serverless deployment, use the BrowserManager class directly and provide a custom executablePath:

Platform-Specific Guides

Vercel

Deploy as a Vercel Function with @sparticuz/chromium. Installation:
Example API Route (api/screenshot.ts):
vercel.json configuration:
Notes:
  • Increase memory to at least 3008 MB for Chromium
  • Increase maxDuration if operations take longer than 10s
  • Cold starts can take 5-10 seconds

AWS Lambda

Deploy using Lambda Functions with @sparticuz/chromium. Installation:
Lambda Handler (index.ts):
Configuration (serverless.yml or SAM template):
Notes:
  • Set memory to at least 3008 MB
  • Set timeout to at least 30 seconds
  • Lambda’s /tmp directory has 512 MB limit; Chromium uses it for downloads and caching
  • @sparticuz/chromium is optimized for Lambda and includes necessary shared libraries

AWS Lambda with Docker

For more control, use a Lambda container image: Dockerfile:
Build and deploy:

Google Cloud Functions

Installation:
Function Handler (index.ts):
Deploy:

Testing Serverless Setup Locally

Before deploying, test your serverless setup locally to verify @sparticuz/chromium integration:
See test/serverless.test.ts in the source code for a complete example.

Performance Optimization

Reduce Cold Start Time

  1. Use deployment packages: Pre-bundle dependencies to reduce cold start
  2. Minimize dependencies: Only include what you need
  3. Use provisioned concurrency (AWS Lambda) for zero cold starts
  4. Keep functions warm with periodic invocations

Memory and CPU Allocation

Chromium requires significant resources:
  • Minimum: 1024 MB memory (will be slow)
  • Recommended: 2048-3008 MB memory for better performance
  • CPU: Scales with memory on most platforms

Reuse Browser Instances

Warning: Reusing browser instances across invocations can cause memory leaks and stale state. Safe approach:

Alternatives to @sparticuz/chromium

chrome-aws-lambda

Older alternative, less maintained:

System Chrome/Chromium

If your serverless environment has Chrome/Chromium pre-installed:

Cloud Browser Services

For production deployments, consider cloud browser services instead of running Chromium in serverless functions:

Browserbase

See Browserbase integration for details.

Browser Use

See Browser Use integration for details.

Kernel

See Kernel integration for details.

Environment Variables

Key environment variables for serverless deployment:

Troubleshooting

”Failed to launch browser” errors

Ensure:
  1. Memory is sufficient (at least 1024 MB, recommended 2048+ MB)
  2. Timeout is adequate (at least 30 seconds)
  3. executablePath is correct:

Missing shared libraries

@sparticuz/chromium includes necessary libraries for Lambda. For other platforms, install system dependencies:

Timeout on first invocation

Cold starts can take 5-10 seconds. Increase function timeout to at least 30 seconds.

Out of memory errors

Increase function memory allocation or use cloud browser services instead. See Troubleshooting for more common issues.