Просмотр исходного кода

Fix sandbox user ID on windows (#170)

* set user id

* fix lint
Robert Brennan 2 лет назад
Родитель
Сommit
815b78595a
1 измененных файлов с 8 добавлено и 2 удалено
  1. 8 2
      opendevin/sandbox/sandbox.py

+ 8 - 2
opendevin/sandbox/sandbox.py

@@ -13,6 +13,13 @@ OutputType = namedtuple("OutputType", ["content"])
 
 
 CONTAINER_IMAGE = os.getenv("SANDBOX_CONTAINER_IMAGE", "opendevin/sandbox:v0.1")
 CONTAINER_IMAGE = os.getenv("SANDBOX_CONTAINER_IMAGE", "opendevin/sandbox:v0.1")
 
 
+
+USER_ID = 1000
+if os.getenv("SANDBOX_USER_ID") is not None:
+    USER_ID = int(os.getenv("SANDBOX_USER_ID", ""))
+elif hasattr(os, "getuid"):
+    USER_ID = os.getuid()
+
 class DockerInteractive:
 class DockerInteractive:
 
 
     def __init__(
     def __init__(
@@ -48,10 +55,9 @@ class DockerInteractive:
         self.container_name = f"sandbox-{self.instance_id}"
         self.container_name = f"sandbox-{self.instance_id}"
 
 
         self.restart_docker_container()
         self.restart_docker_container()
-        uid = os.getuid()
         exit_code, logs = self.container.exec_run([
         exit_code, logs = self.container.exec_run([
             '/bin/bash', '-c',
             '/bin/bash', '-c',
-            f'useradd --shell /bin/bash -u {uid} -o -c \"\" -m devin'
+            f'useradd --shell /bin/bash -u {USER_ID} -o -c \"\" -m devin'
             ],
             ],
             workdir="/workspace"
             workdir="/workspace"
         )
         )