Overview
OpenHands provides a secrets manager that allows you to securely store and manage sensitive information that can be accessed by the agent during runtime, such as API keys. These secrets are automatically exported as environment variables in the agent’s runtime environment.Accessing the Secrets Manager
Navigate to theSettings > Secrets page. Here, you’ll see a list of all your existing custom secrets.
Adding a New Secret
- Click
Add a new secret. - Fill in the following fields:
- Name: A unique identifier for your secret (e.g.,
AWS_ACCESS_KEY). This will be the environment variable name. - Value: The sensitive information you want to store.
- Description (optional): A brief description of what the secret is used for, which is also provided to the agent.
- Name: A unique identifier for your secret (e.g.,
- Click
Add secretto save.
Editing a Secret
- Click the
Editbutton next to the secret you want to modify. - Update its name, value, or description.
- Save the changes.
Deleting a Secret
- Click the
Deletebutton next to the secret you want to remove. - Select
Confirmto delete the secret.
Using Secrets in the Agent
- All custom secrets are automatically exported as environment variables in the agent’s runtime environment.
- You can access them in your code using standard environment variable access methods. For example, if you create a
secret named
OPENAI_API_KEY, you can access it in your code asprocess.env.OPENAI_API_KEYin JavaScript oros.environ['OPENAI_API_KEY']in Python.
Agent-Requested Secrets
Secrets saved inSettings > Secrets reach conversations that start after the save. During a conversation, the agent can also ask for a credential it needs for the current task.
The agent uses its request_secret tool to ask for a secret. The request appears as a The agent needs a secret card inline in the chat, immediately after the tool call, with the agent’s reason for the request and a prefilled name.
The request does not block the conversation: the agent can keep working on anything that does not need the secret while the card is pending, and you can answer whenever you are ready. The card stays in place if you reload the conversation.
When you fill in the value and select Add secret:
- The secret is saved to your secrets and attached to the running conversation, so the agent can use it right away.
- The agent receives only a status result. The secret value never appears in the chat, in the agent’s events, or in the tool arguments.
- If you select
Cancel, the agent is told the request was not saved, and no secret is created.
Settings > Secrets to save the credential and start a new conversation.
Configuring Secrets for Common Git Providers
GitHub Setup
OpenHands automatically exports aGITHUB_TOKEN to the shell environment if provided:
Setting Up a GitHub Token
Setting Up a GitHub Token
- Generate a Personal Access Token (PAT):
- On GitHub, go to
Settings > Developer Settings > Personal Access Tokens. - Tokens (classic)
- Required scopes:
repo(Full control of private repositories)
- Required scopes:
- Fine-grained tokens
- All Repositories (You can select specific repositories, but this will impact what returns in repo search)
- Minimal Permissions (Select
Meta Data = Read-onlyread for search,Pull Requests = Read and WriteandContent = Read and Writefor branch creation)
- Enter token in OpenHands:
- Navigate to the
Settings > Integrationspage. - Paste your token in the
GitHub Tokenfield. - Click
Save Changesto apply the changes.
- Check organization requirements:
- Organization admins may enforce specific token policies.
- Some organizations require tokens to be created with SSO enabled.
- Review your organization’s token policy settings.
- Verify organization access:
- Go to your token settings on GitHub.
- Look for the organization under
Organization access. - If required, click
Enable SSOnext to your organization. - Complete the SSO authorization process.
Troubleshooting
Troubleshooting
-
Token Not Recognized:
- Check that the token hasn’t expired.
- Verify the token has the required scopes.
- Try regenerating the token.
-
Organization Access Denied:
- Check if SSO is required but not enabled.
- Verify organization membership.
- Contact organization admin if token policies are blocking access.
GitLab Setup
OpenHands automatically exports aGITLAB_TOKEN to the shell environment if provided:
Setting Up a GitLab Token
Setting Up a GitLab Token
- Generate a Personal Access Token (PAT):
- On GitLab, go to
User Settings > Access Tokens. - Create a new token with the following scopes:
api(API access)read_user(Read user information)read_repository(Read repository)write_repository(Write repository)
- Set an expiration date or leave it blank for a non-expiring token.
- Enter token in OpenHands:
- Navigate to the
Settings > Integrationspage. - Paste your token in the
GitLab Tokenfield. - Click
Save Changesto apply the changes.
- (Optional): Restrict agent permissions
- Create another PAT using Step 1 and exclude
apiscope . - In the
Settings > Secretspage, create a new secretGITLAB_TOKENand paste your lower scope token. - OpenHands will use the higher scope token, and the agent will use the lower scope token.
Troubleshooting
Troubleshooting
-
Token Not Recognized:
- Check that the token hasn’t expired.
- Verify the token has the required scopes.
-
Access Denied:
- Verify project access permissions.
- Check if the token has the necessary scopes.
- For group/organization repositories, ensure you have proper access.
BitBucket Setup
Setting Up a Bitbucket Password
Setting Up a Bitbucket Password
- Generate an App password:
- On Bitbucket, go to
Account Settings > App Password. - Create a new password with the following scopes:
account:readrepository: writepull requests: writeissues: write
- App passwords are non-expiring token. OpenHands will migrate to using API tokens in the future.
- On Bitbucket, go to
- Enter token in OpenHands:
- Navigate to the
Settings > Integrationspage. - Paste your token in the
BitBucket Tokenfield. - Click
Save Changesto apply the changes.
Troubleshooting
Troubleshooting
- Token Not Recognized:
- Check that the token hasn’t expired.
- Verify the token has the required scopes.

