Registry / llm-agents / openhands-sdk

openhands-sdk

JSON →
library1.44.1pypypi✓ verified 22d ago

The OpenHands SDK is a composable Python library providing core functionality for building AI agents that work with code. It enables defining agents in code and running them locally or at scale in the cloud, serving as the engine behind OpenHands CLI and OpenHands Cloud. As of version 1.16.1, it focuses on modularity, extensibility, and production readiness, with frequent releases aimed at enhanced capabilities and improved user experience.

pip install openhands-sdk
INSTALL
IMPORT
SIG · OPENHANDS-SDK
O
openhands-sdk
llm-agentspythonv1.44.1
Install
27.9s avg
Import
24002ms
Disk
430MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.44.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✕ build_error
py 3.11
✕ build_error
✕ build_error
py 3.12
✓ —
✓ 27.9s
py 3.13
✓ —
✓ 27.9s
py 3.9
✕ build_error
✕ build_error
430MB installed
● package 430MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LLM
from openhands.sdk import LLM
Agent
from openhands.sdk import Agent
Conversation
from openhands.sdk import Conversation
Tool
from openhands.sdk import Tool
FileEditorTool
from openhands.tools.file_editor import FileEditorTool
from openhands.sdk.tools.file_editor import FileEditorTool
Tools are now in the separate `openhands-tools` package as of V1 for modularity.
TerminalTool
from openhands.tools.terminal import TerminalTool
from openhands.sdk.tools.terminal import TerminalTool
Tools are now in the separate `openhands-tools` package as of V1 for modularity.

This quickstart initializes an LLM, an agent with basic tools (Terminal, FileEditor, TaskTracker), and runs a conversation to perform a file-writing task in the current working directory. Ensure `openhands-tools` is installed and `LLM_API_KEY` and `LLM_MODEL` environment variables are set.

import os from openhands.sdk import LLM, Agent, Conversation, Tool from openhands.tools.file_editor import FileEditorTool from openhands.tools.task_tracker import TaskTrackerTool from openhands.tools.terminal import TerminalTool # Ensure LLM_API_KEY and LLM_MODEL are set in your environment # Example: export LLM_API_KEY='your_api_key' / export LLM_MODEL='anthropic/claude-sonnet-4-5-20250929' llm_api_key = os.environ.get('LLM_API_KEY', '') llm_model = os.environ.get('LLM_MODEL', 'anthropic/claude-sonnet-4-5-20250929') # Placeholder model llm = LLM(model=llm_model, api_key=llm_api_key) agent = Agent( llm=llm, tools=[ Tool(name=TerminalTool.name), Tool(name=FileEditorTool.name), Tool(name=TaskTrackerTool.name), ], ) cwd = os.getcwd() conversation = Conversation(agent=agent, workspace=cwd) print(f"Agent will operate in: {cwd}") conversation.send_message("Write 3 facts about the current project into FACTS.txt.") conversation.run() print("All done!")
openhands --version
Debug
Known issues
breakingOpenHands V1, which includes this SDK, represents a significant architectural redesign from V0. Older conversations, CLI, and web API configurations are not directly compatible, and changes were made to package management (from poetry to uv) and modularity. Users upgrading from pre-V1 versions should expect to adapt their code and configurations.
fix
Review the OpenHands V1 migration guide (if available) and adapt configurations, imports, and agent definitions to the new modular structure and API. Ensure `openhands-tools` is installed for common agent tools.
affects: <1.0.0
gotchaCommon agent tools like `FileEditorTool`, `TerminalTool`, and `TaskTrackerTool` are now part of the separate `openhands-tools` package, not `openhands-sdk`. Attempting to import them directly from `openhands.sdk.tools` will result in an `ImportError`.
fix
Install `openhands-tools` (`pip install openhands-tools`) and import tools from `from openhands.tools.*`.
affects: >=1.0.0
gotchaThe SDK relies on environment variables like `LLM_API_KEY` and `LLM_MODEL` for LLM configuration. Ensure these are securely managed and correctly set, especially when deploying agents to different environments. A security fix in v1.12.0 for the agent-server highlighted the importance of not inadvertently forwarding sensitive API keys.
fix
Always use `os.environ.get()` to retrieve API keys and other sensitive configurations. Follow security best practices for credential management in your deployment environment (e.g., Kubernetes secrets, AWS Secrets Manager).
affects: All versions
deprecatedOlder, monolithic components like the `openhands-aci` (Agent Computer Interface) repository have been deprecated, with their functionalities (e.g., file editor tools) migrated into the `openhands-sdk` or `openhands-tools` packages. Relying on deprecated external repositories may lead to outdated or unsupported features.
fix
Migrate to the equivalent functionalities within the `openhands-sdk` and `openhands-tools` packages, referring to the latest documentation for correct usage.
affects: <1.0.0
Errors
Common errors & fixes
RuntimeError: LLM provided a security_risk but no security analyzer is configured - THIS SHOULD NOT HAPPEN!
This error occurs when the LLM's response includes a 'security_risk' parameter, but the OpenHands SDK agent's conversation configuration does not have a security analyzer enabled to handle it. This often happens when confirmation mode is disabled, which can inadvertently remove the security analyzer.
fix
Ensure that a security analyzer is configured for the agent, even if confirmation mode is disabled. This might involve adjusting the agent's setup to always include the security analyzer, or updating the LLM's system prompt to avoid returning 'security_risk' parameters when an analyzer isn't present. For CLI users, ensure your configuration does not inadvertently disable the security analyzer.
Launch docker client failed. Please make sure you have installed docker and started docker desktop/daemon.
OpenHands SDK agents typically run within a sandboxed Docker environment. This error indicates that the Docker daemon is either not running or not accessible to the OpenHands application, preventing the agent from launching its execution environment.
fix
Verify that Docker Desktop (on Windows/macOS) or the Docker daemon (on Linux) is installed and actively running. You can check this by running `docker ps` in your terminal. For Docker Desktop, ensure 'Allow the default Docker socket to be used' is enabled in settings.
PermissionError: [Errno 13] Permission denied: '~/.openhands'
This error occurs when OpenHands attempts to access or modify files within the `~/.openhands` directory, but the current user lacks the necessary read/write permissions. This can happen if the directory was created with root privileges or has incorrect ownership.
fix
Change the ownership of the `~/.openhands` directory to your user account using `sudo chown <user>:<user> ~/.openhands` or update its permissions using `sudo chmod 777 ~/.openhands`. Alternatively, if no previous data is needed, you can delete the directory, and OpenHands will recreate it with the correct permissions.
LLMContextWindowExceedError
This exception is raised when the conversation history exceeds the maximum context window of the configured Large Language Model (LLM), and a 'condenser' is not configured to summarize older history.
fix
Implement a 'condenser' in your agent's configuration. The condenser is designed to summarize older conversation history, allowing the conversation to continue without exceeding the LLM's context window. Example: `conversation = Conversation(agent=agent, condenser=my_condenser_instance)`.
AttributeError: 'list' object has no attribute 'model_dump'
This `AttributeError` typically arises within the `litellm` library, which OpenHands SDK uses for LLM integration. It suggests that a list object was received where a Pydantic model (expected to have a `model_dump` method) was anticipated, likely due to an unexpected format in the LLM's response or a mismatch in how `litellm` processes the output for certain models (e.g., Gemini-2.5-Pro).
fix
This often points to an incompatibility or an unexpected response format from the LLM when integrated via `litellm`. Check the specific LLM model and `litellm` version being used. Ensure `litellm` is up to date, and if the issue persists, review the LLM's output for unexpected structures. It might require adjustments to the prompt or a specific `litellm` configuration to correctly parse the LLM's response.
Upgrade
Version history
1.44.1latest on PyPI · released Aug 28, 2026
Audit
Dependencies
openhands-toolsoptionalProvides essential pre-defined tools like `FileEditorTool` and `TerminalTool` for agents, separated from the core SDK since V1.
litellmrequiredUsed by the SDK's `LLM` class for interacting with various language models.
Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
openhands-sdk — pip install openhands-sdk · libregistry