Skip to main content
A Function can read only the secrets that you attach to it. When an invocation starts, Browserbase loads the attached values into context.secrets. Before you begin, create a secret and create a Functions project with the Functions quickstart. The SDK examples use @browserbasehq/sdk for Node.js and browserbase for Python.

Attach and use a secret

1

Read the secret in the handler

Read the value from context.secrets with the name that you chose when you created the secret:
Node.js
Function secrets are not environment variables. Read attached secrets from context.secrets, not process.env.
2

Publish the Function

Publish the entrypoint:
The command prints the Function ID. Save it for the next step.
3

Attach the secret

Pass the Function ID and secret ID:
The Function and secret must belong to the same Browserbase project.The list contains metadata only. It does not contain secret values.
4

Invoke the Function

Invoke the deployed Function:
Browserbase loads the attached values when the invocation starts. The handler reads them from context.secrets.
Function attachments apply only to deployed invocations. The local development server does not load them.Use a local environment variable as a development fallback:
Node.js
Don’t commit local secret values or .env files.

Update an attached secret

Update the secret by ID:
The update keeps the same secret ID and Function attachments. New invocations use the new value.

Detach a secret

Remove the Function’s access without deleting the secret:
Later invocations no longer receive the detached secret.

Troubleshooting

Next steps

Manage secrets

Create, inspect, update, and delete secrets.

Invoke a Function

Pass parameters and retrieve asynchronous results.