如何安装(2/2)
Install and run an OpenHands Agent Server on your machine, then connect to it from the SDK.
Run a local Agent Server when you want a backend process to host OpenHands conversations over HTTP and WebSocket. This is the simplest setup for testing Agent Canvas-style backends, local integrations, and client-server SDK applications.
Install
Create a Python environment and install the server package and its SDK dependencies:
uv venv
source .venv/bin/activate
uv pip install -U \
openhands-sdk \
openhands-tools \
openhands-workspace \
openhands-agent-server
If you are working from the OpenHands/software-agent-sdk repository, see Agent Server Package § Install for the uv-based setup.
Start Without Authentication
For local development on your own machine, start the server on loopback:
python -m openhands.agent_server --host 127.0.0.1 --port 8000
Verify that it is running:
curl http://127.0.0.1:8000/health
Open the API docs at http://127.0.0.1:8000/docs.
If SESSION_API_KEY (legacy alias) or OH_SESSION_API_KEYS_* is already set in your shell, the server will require that key for /api/* requests. Unset those variables for unauthenticated local-only testing.
This unauthenticated mode is only appropriate for local development. Do not bind an unauthenticated server to a public or shared network interface.
Start With an API Key
Set a session API key before starting the server:
export OH_SESSION_API_KEYS_0="$(openssl rand -hex 32)"
export OH_SECRET_KEY="$(openssl rand -hex 32)"
python -m openhands.agent_server --host 127.0.0.1 --port 8000
Requests to /api/* must include the session key. This request returns the conversation count when the key is accepted:
curl \
-H "X-Session-API-Key: $OH_SESSION_API_KEYS_0" \
http://127.0.0.1:8000/api/conversations/count
OH_SECRET_KEY encrypts sensitive values stored with conversations, including LLM API keys and secrets. Keep it stable across restarts. If it changes, previously encrypted values cannot be restored.
Connect From the SDK
Use Workspace(host=..., api_key=...) to connect SDK code to the server:
import os
from pydantic import SecretStr
from openhands.sdk import Conversation, LLM, Workspace
from openhands.tools.preset.default import get_default_agent
llm = LLM(
model=os.environ.get("LLM_MODEL", "anthropic/claude-sonnet-4-5-20250929"),
api_key=SecretStr(os.environ["LLM_API_KEY"]),
)
agent = get_default_agent(llm=llm, cli_mode=True) # disable browser-automation tools
workspace = Workspace(
host="http://127.0.0.1:8000",
api_key=os.environ["OH_SESSION_API_KEYS_0"],
working_dir="workspace/project",
)
conversation = Conversation(agent=agent, workspace=workspace)
conversation.send_message("Create a NOTES.md file with three facts about this project.")
conversation.run()
conversation.close()
If the server was started without OH_SESSION_API_KEYS_0, remove the api_key=... argument.
The working_dir value is relative to the server's process working directory. See Runtime Files for the default directory layout.
Connect From Another Service
For a non-SDK backend service, pass the session API key as X-Session-API-Key:
curl \
-H "X-Session-API-Key: $OH_SESSION_API_KEYS_0" \
-H "Content-Type: application/json" \
http://127.0.0.1:8000/api/conversations/count
Keep the Agent Server bound to 127.0.0.1 when the backend runs on the same machine. If the backend runs on another host, use a private network or reverse proxy, enable TLS, and restrict network access to trusted callers.
For CORS configuration and running directly from a checkout of OpenHands/software-agent-sdk, see the Agent Server Package page.
Ready-to-Run Example
This example is available on GitHub: examples/02_remote_agent_server/01_convo_with_local_agent_server.py.
The example starts a local Agent Server subprocess, waits for it to become healthy, connects with Workspace(host=...), and runs a RemoteConversation.
You can run the example code as-is.
The model name should follow the LiteLLM convention: provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o).
The LLM_API_KEY should be the API key for your chosen provider.
ChatGPT Plus/Pro subscribers: You can use LLM.subscription_login() to authenticate with your ChatGPT account and access Codex models without consuming API credits. See the LLM Subscriptions guide for details.
Troubleshooting
- 401 Unauthorized: Check that the client sends
X-Session-API-Keyand that it matchesOH_SESSION_API_KEYS_0. - Secrets are missing after restart: Set a stable
OH_SECRET_KEYbefore starting the server. - The server is reachable locally but not from another machine: Use
--host 0.0.0.0only behind trusted network controls, then check firewall and proxy rules. - CORS errors in a browser: Set
OH_ALLOW_CORS_ORIGINS_0to the browser app origin. - Port conflict: Start with another port, for example
--port 8001.
Next Steps
- Agent Server Package - Installation, security, and operational guidance.
- Docker Sandboxed Server - Run the server in an isolated Docker workspace.
- API Sandboxed Server - Start hosted runtime workspaces.
- Agent Server API Reference - Browse generated endpoint docs.
This guide walks you through the process of installing OpenHands Cloud for your GitLab repositories. Once set up, it will allow OpenHands to work with your GitLab repository through the Cloud UI or straight from GitLab!.
Prerequisites
- Signed in to OpenHands Cloud with a GitLab account.
Adding GitLab Repository Access
Upon signing into OpenHands Cloud with a GitLab account, OpenHands will have access to your repositories.
Working With GitLab Repos in Openhands Cloud
After signing in with a Gitlab account, use the Open Repository section to select the appropriate repository and
branch you'd like OpenHands to work on. Then click on Launch to start the conversation!
<img alt="Connect Repo" />
Using Tokens with Reduced Scopes
OpenHands requests an API-scoped token during OAuth authentication. By default, this token is provided to the agent.
To restrict the agent's permissions, you can define a custom secret GITLAB_TOKEN,
which will override the default token assigned to the agent. While the high-permission API token is still requested
and used for other components of the application (e.g. opening merge requests), the agent will not have access to it.
Working on GitLab Issues and Merge Requests Using Openhands
This feature works for personal projects and is available for group projects with a Premium or Ultimate tier subscription.
A webhook is automatically installed within a few minutes after the owner/maintainer of the project or group logs into OpenHands Cloud.
Giving GitLab repository access to OpenHands also allows you to work on GitLab issues and merge requests directly.
Working with Issues
On your repository, label an issue with openhands or add a message starting with @openhands. OpenHands will:
- Comment on the issue to let you know it is working on it.
- You can click on the link to track the progress on OpenHands Cloud.
- Open a merge request if it determines that the issue has been successfully resolved.
- Comment on the issue with a summary of the performed tasks and a link to the PR.
Working with Merge Requests
To get OpenHands to work on merge requests, mention @openhands in the comments to:
- Ask questions
- Request updates
- Get code explanations
Managing GitLab Webhooks
The GitLab webhook management feature allows you to view and manage webhooks for your GitLab projects and groups directly from the OpenHands Cloud Integrations page.
Accessing Webhook Management
The webhook management table is available on the Integrations page when:
- You are signed in to OpenHands Cloud with a GitLab account
- Your GitLab token is connected
To access it:
- Navigate to the
Settings > Integrationspage - Find the GitLab section
- If your GitLab token is connected, you'll see the webhook management table below the connection status
Viewing Webhook Status
The webhook management table displays GitLab groups and individual projects (not associated with any groups) that are accessible to OpenHands.
- Resource: The name and full path of the project or group
- Type: Whether it's a "project" or "group"
- Status: The current webhook installation status:
- Installed: The webhook is active and working
- Not Installed: No webhook is currently installed
- Failed: A previous installation attempt failed (error details are shown below the status)
Reinstalling Webhooks
If a webhook is not installed or has failed, you can reinstall it:
- Find the resource in the webhook management table
- Click the
Reinstallbutton in the Action column - The button will show
Reinstalling...while the operation is in progress - Once complete, the status will update to reflect the result
To reinstall an existing webhook, you must first delete the current webhook from the GitLab UI before using the Reinstall button in OpenHands Cloud.
Important behaviors:
- The Reinstall button is disabled if the webhook is already installed
- Only one reinstall operation can run at a time
- After a successful reinstall, the button remains disabled to prevent duplicate installations
- If a reinstall fails, the error message is displayed below the status badge
- The resources list automatically refreshes after a reinstall completes
Constraints and Limitations
- The webhook management table only displays resources that are accessible with your connected GitLab token
- Webhook installation requires Admin or Owner permissions on the GitLab project or group
Next Steps
- Learn about the Cloud UI.
- Use the Cloud API to programmatically interact with OpenHands.
High level overview of configuring the OpenHands Web interface.
Prerequisites
Launching the GUI Server
Using the CLI Command
You can launch the OpenHands GUI server directly from the command line using the serve command:
Prerequisites: You need to have the OpenHands CLI installed first, OR have uv
installed and run uv tool install openhands --python 3.12 and openhands serve. Otherwise, you'll need to use Docker
directly (see the Docker section below).
openhands serve
This command will:
- Check that Docker is installed and running
- Pull the required Docker images
- Launch the OpenHands GUI server at http://localhost:3000
- Use the same configuration directory (
~/.openhands) as the CLI mode
Mounting Your Current Directory
To mount your current working directory into the GUI server container, use the --mount-cwd flag:
openhands serve --mount-cwd
This is useful when you want to work on files in your current directory through the GUI. The directory will be mounted at /workspace inside the container.
Using GPU Support
If you have NVIDIA GPUs and want to make them available to the OpenHands container, use the --gpu flag:
openhands serve --gpu
This will enable GPU support via nvidia-docker, mounting all available GPUs into the container. You can combine this with other flags:
openhands serve --gpu --mount-cwd
Prerequisites for GPU support:
- NVIDIA GPU drivers must be installed on your host system
- NVIDIA Container Toolkit (nvidia-docker2) must be installed and configured
Requirements
Before using the openhands serve command, ensure that:
- Docker is installed and running on your system
- You have internet access to pull the required Docker images
- Port 3000 is available on your system
The CLI will automatically check these requirements and provide helpful error messages if anything is missing.
Using Docker Directly
Alternatively, you can run the GUI server using Docker directly. See the local setup guide for detailed Docker instructions.
Overview
Initial Setup
- Upon first launch, you'll see a settings popup.
- Select an
LLM ProviderandLLM Modelfrom the dropdown menus. If the required model does not exist in the list, selectsee advanced settings. Then toggleAdvancedoptions and enter it with the correct prefix in theCustom Modeltext box. - Enter the corresponding
API Keyfor your chosen provider. - Click
Save Changesto apply the settings.
Settings
You can use the Settings page at any time to:
- Setup the LLM provider and model for OpenHands.
- Setup the search engine.
- Configure MCP servers.
- Connect to GitHub, connect to GitLab and connect to Bitbucket.
- Set application settings like your preferred language, notifications and other preferences.
- Manage custom secrets.
Key Features
For an overview of the key features available inside a conversation, please refer to the Key Features section of the documentation.
Other Ways to Run Openhands
Deploy OpenHands Enterprise into your own Kubernetes cluster using Helm
OpenHands Enterprise can be deployed into an existing Kubernetes cluster using Helm. This approach gives you full control over the deployment and is ideal for teams with Kubernetes expertise who want to integrate OpenHands into their existing infrastructure.
If you prefer a simpler installation, see the Quick Start guide for VM-based deployment.
When to Use This Approach
Choose the Kubernetes installation path when you:
- Have an existing Kubernetes cluster you want to deploy into
- Need fine-grained control over resource allocation and scaling
- Want to integrate with existing infrastructure (external PostgreSQL, Redis, S3)
- Have a platform team familiar with Helm and Kubernetes operations
- Need to comply with specific infrastructure policies or constraints
Architecture Overview
OpenHands Enterprise consists of several components deployed as Kubernetes workloads:
<img alt="OpenHands Enterprise Architecture" />
Core Components
| Component | Description |
|---|---|
| OpenHands Server | Main application server handling UI, API, and agent orchestration |
| Runtime API | Manages sandbox lifecycle: provisioning, scaling, and cleanup |
| Runtimes (Sandboxes) | Isolated containers where agents execute code |
| Keycloak | Identity and access management |
| LiteLLM Proxy | Routes requests to your LLM provider(s) |
| PostgreSQL | Persistent storage for application data |
| Redis | Caching and session management |
Supporting Services
| Component | Description |
|---|---|
| Conversation Bucket | S3-compatible storage for conversation history |
| Image Loader | Pre-loads runtime container images on nodes |
Guides
Size your node pools, volume storage, and database from peak concurrent sandboxes.
End-to-end installation instructions using your OpenHands Enterprise license.
Install the Sysbox runtime so agent sandboxes can run securely.
Automate DNS records and TLS certificates with external-dns and cert-manager.
Prepare an Amazon EKS cluster to run OpenHands Enterprise.
Configure OpenHands to use your own PostgreSQL database instead of the bundled instance.
Configure memory, CPU, and storage for optimal performance.
Generic advice for upgrading the Kubernetes cluster underneath OpenHands.
Request Access
Kubernetes-based installation is currently available to select customers on request. If you're interested in deploying OpenHands Enterprise into your own Kubernetes cluster, please contact our team to discuss your requirements.
Get in touch with our team to request access to Kubernetes installation.
Install the OpenHands CLI on your system
Windows users: All commands below should be run inside the WSL terminal (Ubuntu). Use wsl -d Ubuntu in PowerShell or search "Ubuntu" in the Start menu to access the Ubuntu terminal. We also have a step-by-step video tutorial available.
Installation Methods
Requires Python 3.12+ and [uv](https://docs.astral.sh/uv/) installed.
**Install OpenHands:**
uv tool install openhands --python 3.12
**Run OpenHands:**
openhands
**Upgrade OpenHands:**
uv tool upgrade openhands --python 3.12
Install the OpenHands CLI binary with the install script:
curl -fsSL https://install.openhands.dev/install.sh | sh
Then run:
openhands
Your system may require you to allow permissions to run the executable.
When running the OpenHands CLI on Mac, you may get a warning that says "openhands can't be opened because Apple
cannot check it for malicious software."
1. Open `System Settings`.
2. Go to `Privacy & Security`.
3. Scroll down to `Security` and click `Allow Anyway`.
4. Rerun the OpenHands CLI.
<img alt="mac-security" />
1. Set the following environment variable in your terminal:
* `SANDBOX_VOLUMES` to specify the directory you want OpenHands to access ([See using SANDBOX\_VOLUMES for more info](https://docs.openhands.dev/openhands/usage/sandboxes/docker#using-sandbox_volumes))
2. Ensure you have configured your settings before starting:
* Set up `~/.openhands/settings.json` with your LLM configuration
3. Run the following command:
docker run -it \
--pull=always \
-e AGENT_SERVER_IMAGE_REPOSITORY=ghcr.io/openhands/agent-server \
-e AGENT_SERVER_IMAGE_TAG=1.26.0-python \
-e SANDBOX_USER_ID=$(id -u) \
-e SANDBOX_VOLUMES=$SANDBOX_VOLUMES \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.openhands:/root/.openhands \
--add-host host.docker.internal:host-gateway \
--name openhands-cli-$(date +%Y%m%d%H%M%S) \
python:3.12-slim \
bash -c "pip install uv && uv tool install openhands --python 3.12 && openhands"
The `-e SANDBOX_USER_ID=$(id -u)` is passed to the Docker command to ensure the sandbox user matches the host user's
permissions. This prevents the agent from creating root-owned files in the mounted workspace.
First Run
The first time you run the CLI, it will take you through configuring the required LLM settings. These will be saved
for future sessions in ~/.openhands/settings.json.
The conversation history will be saved in ~/.openhands/conversations.
If you're upgrading from a CLI version before release 1.0.0, you'll need to redo your settings setup as the configuration format has changed.
Next Steps
- Quick Start - Learn the basics of using the CLI
- MCP Servers - Configure MCP servers
This guide walks you through the process of installing OpenHands Cloud for your GitHub repositories. Once set up, it will allow OpenHands to work with your GitHub repository through the Cloud UI or straight from GitHub!
Prerequisites
- Signed in to OpenHands Cloud with a GitHub account.
Adding GitHub Repository Access
You can grant OpenHands access to specific GitHub repositories:
- Click on
+ Add GitHub Reposin the repository selection dropdown. -
Select your organization and choose the specific repositories to grant OpenHands access to.
-
OpenHands requests short-lived tokens (8-hour expiration) with these permissions:
- Actions: Read and write
- Commit statuses: Read and write
- Contents: Read and write
- Issues: Read and write
- Metadata: Read-only
- Pull requests: Read and write
- Webhooks: Read and write
- Workflows: Read and write
-
Repository access for a user is granted based on:
- Permission granted for the repository
- User's GitHub permissions (owner/collaborator)
-
Click
Install & Authorize.
Modifying Repository Access
You can modify GitHub repository access at any time by:
- Selecting
+ Add GitHub Reposin the repository selection dropdown or - Visiting the
Settings > Integrationspage and selectingConfigure GitHub Repositories
Working With GitHub Repos in Openhands Cloud
Once you've granted GitHub repository access, you can start working with your GitHub repository. Use the
Open Repository section to select the appropriate repository and branch you'd like OpenHands to work on. Then click
on Launch to start the conversation!
<img alt="Connect Repo" />
Working on GitHub Issues and Pull Requests Using Openhands
To allow OpenHands to work directly from GitHub directly, you must
give OpenHands access to your repository. Once access is
given, you can use OpenHands by labeling the issue or by tagging @openhands.
Working with Issues
On your repository, label an issue with openhands or add a message starting with @openhands. OpenHands will:
- Comment on the issue to let you know it is working on it.
- You can click on the link to track the progress on OpenHands Cloud.
- Open a pull request if it determines that the issue has been successfully resolved.
- Comment on the issue with a summary of the performed tasks and a link to the PR.
Working with Pull Requests
To get OpenHands to work on pull requests, mention @openhands in the comments to:
- Ask questions
- Request updates
- Get code explanations
The @openhands mention functionality in pull requests only works if the pull request is both
to and from a repository that you have added through the interface. This is because OpenHands needs appropriate
permissions to access both repositories.
Next Steps
- Learn about the Cloud UI.
- Use the Cloud API to programmatically interact with OpenHands.
This guide walks you through installing the OpenHands Slack app.
<iframe title="OpenHands Slack Integration Tutorial" />
OpenHands utilizes a large language model (LLM), which may generate responses that are inaccurate or incomplete. While we strive for accuracy, OpenHands' outputs are not guaranteed to be correct, and we encourage users to validate critical information independently.
Prerequisites
- Access to OpenHands Cloud.
Installation Steps
<AccordionGroup>
**This step is for Slack admins/owners**
1. Make sure you have permissions to install Apps to your workspace.
2. Click the button below to install OpenHands Slack App [https://slack.com/oauth/v2/authorize?client_id=7477886716822.8729519890534&scope=app_mentions:read,channels:history,chat:write,groups:history,im:history,mpim:history,users:read&user_scope=](<img alt="Add to Slack" />)
3. In the top right corner, select the workspace to install the OpenHands Slack app.
4. Review permissions and click allow.
**Make sure your Slack workspace admin/owner has installed OpenHands Slack App first.**
Every user in the Slack workspace (including admins/owners) must link their OpenHands Cloud account to the OpenHands Slack App. To do this:
1. Visit the [Settings > Integrations](https://app.all-hands.dev/settings/integrations) page in OpenHands Cloud.
2. Click `Install OpenHands Slack App`.
3. In the top right corner, select the workspace to install the OpenHands Slack app.
4. Review permissions and click allow.
Depending on the workspace settings, you may need approval from your Slack admin to authorize the Slack App.
</AccordionGroup>
Working With the Slack App
To start a new conversation, you can mention @openhands in a new message or a thread inside any Slack channel.
Once a conversation is started, all thread messages underneath it will be follow-up messages to OpenHands.
To send follow-up messages for the same conversation, mention @openhands in a thread reply to the original message.
You must be the user who started the conversation.
Example conversation
Start a new conversation, and select repo
Conversation is started by mentioning @openhands.
<img alt="slack-create-conversation.png" />
See agent response and send follow up messages
Initial request is followed up by mentioning @openhands in a thread reply.
<img alt="slack-results-and-follow-up.png" />
Pro tip
You can mention a repo name when starting a new conversation in the following formats
- "My-Repo" repo (e.g
@openhands in the openhands repo ...) - "OpenHands/OpenHands" (e.g
@openhands in OpenHands/OpenHands ...)
The repo match is case insensitive. If a repo name match is made, it will kick off the conversation. If the repo name partially matches against multiple repos, you'll be asked to select a repo from the filtered list.
<img alt="slack-pro-tip.png" />
