mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
1.7 KiB
1.7 KiB
Headless Mode
You can run OpenHands with a single command, without starting the web application. This makes it easy to write scripts and automate tasks with OpenHands.
This is different from CLI Mode, which is interactive, and better for active development.
With Python
To run OpenHands in headless mode with Python, follow the Development setup instructions, and then run:
poetry run python -m openhands.core.main -t "write a bash script that prints hi"
You'll need to be sure to set your model, API key, and other settings via environment variables
or the config.toml file.
With Docker
- Set
WORKSPACE_BASEto the directory you want OpenHands to edit:
WORKSPACE_BASE=$(pwd)/workspace
- Set
LLM_MODELto the model you want to use:
LLM_MODEL="anthropic/claude-3-5-sonnet-20241022"
- Set
LLM_API_KEYto your API key:
LLM_API_KEY="sk_test_12345"
- Run the following Docker command:
docker run -it \
--pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.15-nikolaik \
-e SANDBOX_USER_ID=$(id -u) \
-e WORKSPACE_MOUNT_PATH=$WORKSPACE_BASE \
-e LLM_API_KEY=$LLM_API_KEY \
-e LLM_MODEL=$LLM_MODEL \
-e LOG_ALL_EVENTS=true \
-v $WORKSPACE_BASE:/opt/workspace_base \
-v /var/run/docker.sock:/var/run/docker.sock \
--add-host host.docker.internal:host-gateway \
--name openhands-app-$(date +%Y%m%d%H%M%S) \
docker.all-hands.dev/all-hands-ai/openhands:0.15 \
python -m openhands.core.main -t "write a bash script that prints hi"