I'm running open hands under docker on linux for t...
# questions
c
I'm running open hands under docker on linux for the first time, today. On mac this wasn't a problem because I was using docker desktop, but on linux I'm using
systemctl
to start docker. I'm noticing open hands is overwriting my group ownership of every file in the workspace to root. What is the best way to get it to stop doing that?
b
How did you run OpenHands?
c
Copy code
docker run -it --rm \
    -p 3001:3000 \
    -e SANDBOX_USER_ID=$(id -u) \
    -e WORKSPACE_MOUNT_PATH=$WORKSPACE_BASE \
    -v $WORKSPACE_BASE:/opt/workspace_base \
    -e AGENT_ENABLE_PROMPT_EXTENSIONS=false \
    -e LOG_ALL_EVENTS=true \
    -e LLM_NATIVE_TOOL_CALLING=true \
    -e LLM_DISABLE_STOP_WORD=true \
    -e LLM_REASONING_EFFORT=high \
    -v ~/.openhands:/.openhands \
    -v /var/run/docker.sock:/var/run/docker.sock \
    --add-host host.docker.internal:host-gateway \
    -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.59-nikolaik \
    --name openhands-app   \
    --gpus all \
    docker.all-hands.dev/all-hands-ai/openhands:0.59
b
Hmmm I thought
-e SANDBOX_USER_ID=$(id -u)
would run it as the user you are running as so it shouldn't change to root. Not sure. I'll let someone else chime in.
c
That changes the user, but it's still setting the group to root because docker is running as root.
I know there is a way to run docker unprivileged, it's just not the default. If there is no other solution, I'll try that.
I set my workspace to my user home dir and got locked out of ssh because it changed my
~/.ssh
group to root and broke pub key auth. Lesson learned. Do not use homedir.
b
Ouch! facepalm This is likely a legit issue on Linux and needs addressing.
c
oof. seems to be happening even if I set WORKSPACE_BASE to a subdir of my homedir.
same thing happens if I use SANDBOX_VOLUMES
When I try to run
docker run
with
-u $(id -u):$(id -g) \
to limit the uid/gid, I get:
Copy code
/bin/bash: /app/entrypoint.sh: Permission denied
l
Are you using a build that includes this PR? https://github.com/OpenHands/OpenHands/pull/11231
c
huh. that tells me
SANDBOX_GROUP_ID
is an undocumented option. Wild that open hands has access to my entire homedir though.
I'm just going to use rootless docker: https://docs.docker.com/engine/security/rootless/ This seems like the best and easiest solution.
l
You could also use rootless podman, it's supported. You'll have to pass the right socket and use :Z/z for mounts if your distro uses SELinux though.
c
I finally got rootless docker running open hands last night in ubuntu 24.04. It took hours of trial and error to figure out what I had to change. I may still have some issues, but the 3 tricks were: 1. remove
-e SANDBOX_USER_ID=$(id -u) \
If you leave it, your file uids and gids get messed up. Just run open hands as root in the docker container and let rootless docker sort it out. 2. The socket line becomes
-v /run/user/1000/docker.sock:/var/run/docker.sock \
with
1000
being my user id on the ubuntu host. 3. The networking line becomes
--add-host host.docker.internal:192.168.0.144 \
with
192.168.0.144
being the IP of the ubuntu host. This one was the trickiest and took the most time. rootless docker doesn't have
host-gateway
like docker desktop on a Mac. I wouldn't say it's "secure" by any stretch of the imagination, but I don't need it to be since my machine is behind a firewall on a secure network. Here's the final full command to start rootless docker with GPU support (which I still don't have 100% working yet):
Copy code
docker run -it --rm \
    -p 3001:3000 \
    -e WORKSPACE_MOUNT_PATH=$WORKSPACE_BASE \
    -v $WORKSPACE_BASE:/opt/workspace_base \
    -e AGENT_ENABLE_PROMPT_EXTENSIONS=false \
    -e LOG_ALL_EVENTS=true \
    -e LLM_NATIVE_TOOL_CALLING=true \
    -e LLM_DISABLE_STOP_WORD=true \
    -e LLM_REASONING_EFFORT=high \
    -v ~/.openhands:/.openhands \
    -v /run/user/1000/docker.sock:/var/run/docker.sock \
    --add-host host.docker.internal:192.168.0.144 \
    -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.59-nikolaik \
    --name openhands-app \
    --gpus all \
    docker.all-hands.dev/all-hands-ai/openhands:0.59
In my frustration I did briefly try podman. I think it could probably be made to work too, but you have to set more env vars because it doesn't seem to like docker http urls for the runtime. I stuck with rootless docker since I already had it 90% working at the time.
I think I'm going to hack the Dockerfile and build my own CUDA runtime because it takes a while to install all the deps and uses a lot of disk space.
Oh... I also ran into a weird issue where
chown -R
operations under docker take a really long time on ubuntu. Not sure what's up with that, but I made some changes to my MCP server to work around it.
I codified this into https://github.com/OpenHands/OpenHands/issues/11575 so it has more visibility than slack and hopefully saves anyone else who tries this some time.