Functions reference
API reference for invoking, managing, and monitoring Browserbase Functions.
Deploy from playground
Deploy agents and automations directly from the Browserbase Playground.
Overview
Functions let you deploy browser agents or automation scripts directly onto Browserbase’s infrastructure. Start in your local environment, configure agents or write browser scripts, test them instantly, and deploy directly as cloud functions invokable as APIs. Examples: Key benefits:- Zero infrastructure - No servers to manage or containers to configure
- Instant testing - Local development server for rapid iteration
- Run agents - Full serverless sandbox execution environments
- Playwright native - Use familiar Playwright APIs for browser automation
- Built-in browser management - Sessions are automatically created and configured
- API-first - Invoke functions via simple HTTP requests
Quick start
Ready to deploy? Follow the step-by-step guide to deploy your first Function.
Getting started
The easiest way to get started is using the CLI to scaffold a new project:- A configured
package.jsonwith required dependencies - A
tsconfig.jsonfor TypeScript support - A template
.envfile for your credentials - A starter
index.tsfile with an example function
.env file:
Get your API key and Project ID from the Browserbase Dashboard Settings.
Defining Functions
Basic Function
Function parameters
- Function Name - Unique identifier for your function (used in the “invoke function” HTTP request)
- Handler - Async function that receives:
ctx- Context object with session informationparams- Parameters passed when invoking the function
- Options - Optional configuration object for session settings
Context object
Thectx parameter provides access to the browser session:
Function response
Return any JSON-serializable data from your function:Session configuration
Configure browser session settings using the third parameter:Most session creation options are supported in
sessionConfig. See the Create Session API Reference for the full list of available options including proxies, Verified, viewports, contexts, and extensions.Example with Playwright
Here’s a full example that fills out a contact form:Example with agents
Here’s an example that uses Stagehand Agent to deploy a browser agent on Browserbase Functions:Deploy Claude Code
Here’s an example that deploys Claude Code using Anthropic Agent SDK as a browser agent on Browserbase Functions:Local development
Before publishing, you can test your functions locally using the development server. This creates real Browserbase sessions using your credentials, ensuring your function behaves the same locally and in production.Start the development server
http://127.0.0.1:14113 and watches for file changes, automatically reloading when you modify your function files.
Invoke Functions locally
Use curl to test your function against the local development server:my-function with your function’s name (the first parameter passed to defineFn).
Pass parameters locally
Pass parameters to your function using the request body:params argument:
The local development server runs your function synchronously and returns the result directly in the HTTP response. This differs from production, where invocations are asynchronous and require polling for results.
Publishing Functions
Multiple Functions (single file)
Define multiple functions in a single file:index.ts
pnpm bb publish index.ts.
The
publish command requires an “entrypoint” parameter. An entrypoint file indicates that all functions in this
project are either defined in this file or defined in files directly or indirectly imported into this file.Multiple Functions (multiple files)
Define multiple functions in multiple files:index.ts
screenshot-fn.ts
pnpm bb publish index.ts.
Invoke a Function
Get build result
Retrieve information about the Function(s) built or updated by a build:Pass parameters to Functions
Access parameters in your function handler:Async invocation
Function invocations are async. While an invocation is running, you can poll for completion:Best practices
Error handling
Unhandled errors are caught by the runners and reported as an error. If you want to gracefully handle your errors (for example, return information on the failure), wrap your automation code in try-catch blocks:Logging
Use console methods for debugging - logs are captured and available in invocation logs:Session cleanup
Browser sessions automatically close when your function completes. No manual cleanup is required.Monitoring and debugging
Every Function invocation creates a browser session that you can inspect as with any other Browserbase session:- Session recordings - View the function execution in the Session Inspector
- Console logs - See all logged messages during execution
- Network activity - Inspect HTTP requests and responses
- Performance metrics - Monitor execution time and resource usage
Session recordings
Learn how to debug Functions using session recordings
Limitations
- Maximum execution time: 15 minutes
- No persistent storage between invocations
- TypeScript only (no Python support)
- Custom NPM packages must be bundled with your code (private NPM packages aren’t supported)
Secrets
Secrets management for Functions environments is coming soon! You’ll be able to securely store and access sensitive values like API keys, tokens, and credentials within your deployed Functions without passing them as parameters.Availability: Support for Secrets is a top priority on the current roadmap.
This feature isn’t yet available in beta. Email support@browserbase.com to get
on the waitlist.
Next steps
Session configuration
Learn about all available session configuration options
Verified
Configure browser identity for your functions
Browser contexts
Persist authentication and session state
API reference
Complete Browserbase API documentation