Skip to content

Commit 7b6b4e3

Browse files
authored
be more dynamic around uid generation (OpenHands#1584)
* be more dynamic around uid generation * fix comment * fix second uid add
1 parent 24c5bcb commit 7b6b4e3

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

containers/app/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ FROM python:3.12-slim as runtime
3333
WORKDIR /app
3434

3535
ENV RUN_AS_DEVIN=true
36-
ENV OPENDEVIN_USER_ID=1000
36+
# A random number--we need this to be different from the user's UID on the host machine
37+
ENV OPENDEVIN_USER_ID=42420
3738
ENV USE_HOST_NETWORK=false
3839
ENV SSH_HOSTNAME=host.docker.internal
3940
ENV WORKSPACE_BASE=/opt/workspace_base

containers/app/entrypoint.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,23 @@ if [ -z "$SANDBOX_USER_ID" ]; then
1010
exit 1
1111
fi
1212

13+
if [[ "$SANDBOX_USER_ID" -eq 0 ]]; then
14+
echo "SANDBOX_USER_ID cannot be 0. Please run with a different user id."
15+
exit 1
16+
fi
17+
1318
# change uid of opendevin user to match the host user
1419
# but the group id is not changed, so the user can still access everything under /app
15-
useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash enduser
20+
if ! useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash enduser; then
21+
echo "Failed to create user enduser with id $SANDBOX_USER_ID. Moving opendevin user."
22+
incremented_id=$(($SANDBOX_USER_ID + 1))
23+
usermod -u $incremented_id opendevin
24+
if ! useradd -l -m -u $SANDBOX_USER_ID -s /bin/bash enduser; then
25+
echo "Failed to create user enduser with id $SANDBOX_USER_ID for a second time. Exiting."
26+
exit 1
27+
fi
28+
fi
29+
1630
usermod -aG app enduser
1731
mkdir -p /home/enduser/.cache/ms-playwright/
1832
mv /home/opendevin/.cache/ms-playwright/ /home/enduser/.cache/

0 commit comments

Comments
 (0)