All-Hands-AI / OpenHands

🙌 OpenHands: Code Less, Make More
https://all-hands.dev
MIT License
33.09k stars 3.79k forks source link

pexpect/ssh issue when running Docker #1156

Closed talentlo closed 4 months ago

talentlo commented 6 months ago

use docker,the chatbox "Error creating controller. Please check Docker is running using docker ps."

the docker logs:

INFO: Started server process [1] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:3000 (Press CTRL+C to quit) INFO: ('172.28.186.18', 64210) - "WebSocket /ws?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzaWQiOiJiY2FkMjQ5Ny02MzRjLTRkYzMtOGNjZi05NDA0MDJjNjRhOTEifQ.i_NEUWhxv2c9FhioADWKAsbXs09FP23Own8u8PiKb48" [accepted] INFO: connection open Starting loop_recv for sid: bcad2497-634c-4dc3-8ccf-940402c64a91 INFO: 172.28.186.18:64213 - "GET /api/messages/total HTTP/1.1" 200 OK INFO: 172.28.186.18:64212 - "GET /api/configurations HTTP/1.1" 200 OK 08:03:20 - opendevin:INFO: ssh_box.py:271 - Container stopped 08:03:20 - opendevin:WARNING: ssh_box.py:283 - Using port forwarding for Mac OS. Server started by OpenDevin will not be accessible from the host machine at the moment. See https://github.com/OpenDevin/OpenDevin/issues/897 for more information. 08:03:21 - opendevin:INFO: ssh_box.py:309 - Container started 08:03:22 - opendevin:INFO: ssh_box.py:326 - waiting for container to start: 1, container status: running 08:03:22 - opendevin:INFO: ssh_box.py:161 - Connecting to root@host.docker.internal via ssh. If you encounter any issues, you can try ssh -v -p 43729 root@host.docker.internal with the password 'ec60e3dc-d024-4667-bf91-61e6e42f14e8' and report the issue on GitHub. 08:03:23 - opendevin:ERROR: agent.py:127 - Error creating controller: Could not establish connection to host Traceback (most recent call last): File "/app/opendevin/server/agent/agent.py", line 118, in create_controller self.controller = AgentController( ^^^^^^^^^^^^^^^^ File "/app/opendevin/controller/agent_controller.py", line 91, in init self.command_manager = CommandManager(self.id, container_image) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/opendevin/controller/command_manager.py", line 26, in init self.shell = DockerSSHBox( ^^^^^^^^^^^^^ File "/app/opendevin/sandbox/ssh_box.py", line 90, in init self.start_ssh_session() File "/app/opendevin/sandbox/ssh_box.py", line 164, in start_ssh_session self.ssh.login(hostname, username, self._ssh_password, File "/app/.venv/lib/python3.12/site-packages/pexpect/pxssh.py", line 424, in login raise ExceptionPxssh('Could not establish connection to host') pexpect.pxssh.ExceptionPxssh: Could not establish connection to host Mounting workspace directory: /root/work_lcg/OpenDevinDocker INFO: 172.28.186.18:64231 - "GET /index.html HTTP/1.1" 304 Not Modified 08:04:03 - opendevin:INFO: session.py:39 - WebSocket disconnected, sid: bcad2497-634c-4dc3-8ccf-940402c64a91 INFO: connection closed INFO: ('172.28.186.18', 64233) - "WebSocket /ws?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzaWQiOiJiY2FkMjQ5Ny02MzRjLTRkYzMtOGNjZi05NDA0MDJjNjRhOTEifQ.i_NEUWhxv2c9FhioADWKAsbXs09FP23Own8u8PiKb48" [accepted] INFO: connection open Starting loop_recv for sid: bcad2497-634c-4dc3-8ccf-940402c64a91 INFO: 172.28.186.18:64231 - "GET /locales/zh/translation.json HTTP/1.1" 404 Not Found INFO: 172.28.186.18:64231 - "GET /api/refresh-files HTTP/1.1" 200 OK INFO: 172.28.186.18:64232 - "GET /api/messages/total HTTP/1.1" 200 OK INFO: 172.28.186.18:64231 - "GET /api/configurations HTTP/1.1" 200 OK 08:04:05 - opendevin:INFO: ssh_box.py:271 - Container stopped 08:04:05 - opendevin:WARNING: ssh_box.py:283 - Using port forwarding for Mac OS. Server started by OpenDevin will not be accessible from the host machine at the moment. See https://github.com/OpenDevin/OpenDevin/issues/897 for more information. 08:04:05 - opendevin:INFO: ssh_box.py:309 - Container started 08:04:06 - opendevin:INFO: ssh_box.py:326 - waiting for container to start: 1, container status: running 08:04:07 - opendevin:INFO: ssh_box.py:161 - Connecting to root@host.docker.internal via ssh. If you encounter any issues, you can try ssh -v -p 53149 root@host.docker.internal with the password 'ff06749c-5f4f-4313-85c2-762906ed6daf' and report the issue on GitHub. 08:04:08 - opendevin:ERROR: agent.py:127 - Error creating controller: Could not establish connection to host Traceback (most recent call last): File "/app/opendevin/server/agent/agent.py", line 118, in create_controller self.controller = AgentController( ^^^^^^^^^^^^^^^^ File "/app/opendevin/controller/agent_controller.py", line 91, in init self.command_manager = CommandManager(self.id, container_image) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/opendevin/controller/command_manager.py", line 26, in init self.shell = DockerSSHBox( ^^^^^^^^^^^^^ File "/app/opendevin/sandbox/ssh_box.py", line 90, in init self.start_ssh_session() File "/app/opendevin/sandbox/ssh_box.py", line 164, in start_ssh_session self.ssh.login(hostname, username, self._ssh_password, File "/app/.venv/lib/python3.12/site-packages/pexpect/pxssh.py", line 424, in login raise ExceptionPxssh('Could not establish connection to host') pexpect.pxssh.ExceptionPxssh: Could not establish connection to host Mounting workspace directory: /root/work_lcg/OpenDevinDocker INFO: 172.28.186.18:64231 - "GET /api/messages HTTP/1.1" 200 OK

wmitnaj commented 6 months ago

Getting exactly the same error when trying to start opendevin in docker in a windows 11 wsl ubuntu environment

rbren commented 6 months ago

@wmitnaj that's helpful, I'm surprised to hear that docker on WSL has this problem

Setting -e SANDBOX_TYPE=exec may fix the issue for now

SmartManoj commented 6 months ago

@talentlo, In latest version also, you getting this error?

talentlo commented 6 months ago

I tried the new docker image today and the problem is still there

02:34:57 - opendevin:ERROR: agent.py:127 - Error creating controller: Could not establish connection to host Traceback (most recent call last): File "/app/opendevin/server/agent/agent.py", line 118, in create_controller self.controller = AgentController( ^^^^^^^^^^^^^^^^ File "/app/opendevin/controller/agent_controller.py", line 91, in init self.command_manager = CommandManager(self.id, container_image) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/opendevin/controller/command_manager.py", line 26, in init self.shell = DockerSSHBox( ^^^^^^^^^^^^^ File "/app/opendevin/sandbox/ssh_box.py", line 90, in init self.start_ssh_session() File "/app/opendevin/sandbox/ssh_box.py", line 164, in start_ssh_session self.ssh.login(hostname, username, self._ssh_password, File "/app/.venv/lib/python3.12/site-packages/pexpect/pxssh.py", line 424, in login raise ExceptionPxssh('Could not establish connection to host') pexpect.pxssh.ExceptionPxssh: Could not establish connection to host

talentlo commented 6 months ago

@talentlo, In latest version also, you getting this error?

@SmartManoj yes,the problem is still there

razeenbari commented 6 months ago

I tried recent image from docker and this error is still not resolved. if any of you finds any solutions kindly report here. Regards, Muhammad Razeen Bari

rbren commented 6 months ago

@PierrunoYT seems to have solved the issue by restarting his computer. YMMV

If this works for anyone, please report back

PierrunoYT commented 6 months ago

@PierrunoYT seems to have solved the issue by restarting his computer. YMMV

If this works for anyone, please report back

I uninstalled WSL and Docker with the help of AI and then installed everything again.

then runned

Here are all the steps to set up OpenDevin on Ubuntu WSL with Python 3.12.3, Node.js v20.12.2, Docker, and all the requirements:

A. Install WSL2 on Windows

  1. Open PowerShell as an administrator.
  2. Run the following command to install WSL2:
    wsl --install
  3. Restart your computer when prompted.

B. Install Ubuntu on WSL

  1. Open the Microsoft Store.
  2. Search for "Ubuntu" and select the latest version (e.g., Ubuntu 22.04 LTS).
  3. Click "Install" and wait for the installation to complete.

C. Start Ubuntu and set up your user account

  1. Start Ubuntu from the Start menu.
  2. Wait for the installation to complete and you'll be prompted to create a user account.
  3. Enter a username and password for your Ubuntu user account.

D. Update and upgrade Ubuntu packages

  1. Open the Ubuntu terminal.
  2. Run the following commands to update and upgrade the packages:
    sudo apt update
    sudo apt upgrade

E. Install the required dependencies

  1. Install the necessary dependencies with the following command:
    sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git software-properties-common

F. Install Python 3.12.3

  1. Add the Deadsnakes PPA:
    sudo add-apt-repository ppa:deadsnakes/ppa
  2. Press Enter when prompted to continue the process.
  3. Update the package lists:
    sudo apt update
  4. Install Python 3.12.3:
    sudo apt install python3.12
  5. Verify the Python version:
    python3.12 --version
  6. Install pip for Python 3.12.3:
    sudo apt install python3.12-distutils
    curl https://bootstrap.pypa.io/get-pip.py | python3.12
  7. Verify the pip version for Python 3.12.3:
    python3.12 -m pip --version

G. Install Node.js v20.12.2 with nvm

  1. Install cURL:
    sudo apt-get install curl
  2. Download and run the nvm installation script:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
  3. Close and reopen your terminal.
  4. Verify the nvm installation:
    command -v nvm
  5. Install Node.js v20.12.2:
    nvm install 20.12.2
  6. Set Node.js v20.12.2 as the default version:
    nvm alias default 20.12.2
  7. Verify the Node.js and npm versions:
    node -v
    npm -v

H. Install Docker

  1. Install Docker with the following commands:
    sudo apt install apt-transport-https ca-certificates curl software-properties-common
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt update
    sudo apt install docker-ce docker-ce-cli containerd.io
  2. Add your user to the Docker group to avoid using sudo with Docker commands:
    sudo usermod -aG docker $USER
  3. Log out and log back in for the group changes to take effect.

I. Navigate to the desired directory

  1. Open a terminal in Ubuntu.
  2. Navigate to the directory where you want to set up OpenDevin, e.g.:
    cd /mnt/c/Users/pierr/OpenDevin

J. Set up OpenDevin

  1. Set the LLM_API_KEY environment variable with your OpenAI API key or another LLM API key:
    export LLM_API_KEY="sk-..."

    Replace "sk-..." with your actual API key.

  2. Set the WORKSPACE_DIR environment variable to the absolute path of the directory that OpenDevin should modify:
    export WORKSPACE_DIR=$(pwd)/workspace

    This command sets WORKSPACE_DIR to a directory named workspace in the current directory. You can change the path to your preference, but use an absolute path.

K. Start OpenDevin

  1. Start the OpenDevin Docker container with the following command:
    docker run \
       -e LLM_API_KEY \
       -e WORKSPACE_MOUNT_PATH=$WORKSPACE_DIR \
       -v $WORKSPACE_DIR:/opt/workspace_base \
       -v /var/run/docker.sock:/var/run/docker.sock \
       -p 3000:3000 \
       ghcr.io/opendevin/opendevin:0.3.1
  2. Access the OpenDevin web interface by opening a web browser and navigating to http://localhost:3000.

This should have successfully set up and started OpenDevin on Ubuntu WSL with Python 3.12.3, Node.js v20.12.2, Docker, and all the requirements. You can now start developing and exploring OpenDevin!

Remember to keep your API key secure and not share it publicly or in version control systems.

SmartManoj commented 6 months ago

@talentlo, https://github.com/OpenDevin/OpenDevin/blob/0356f6ec89b9b9c827fa84dda83903d716cedd85/opendevin/sandbox/docker/ssh_box.py#L163-L167

Did you try that ssh command?

dagelf commented 6 months ago

I guess this command needs to be run from inside docker... and the issue seems to be the hostname used. Sorry for opening a separate ticket

$ docker exec -ti opendevin-sandbox-03e863eb-5026-47bd-8cd1-ad282cb360cc ssh -v -p 51049 root@host.docker.internal
OpenSSH_8.9p1 Ubuntu-3ubuntu0.7, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
ssh: Could not resolve hostname host.docker.internal: Name or service not known

Edit: Oh wait I see that's forwarded on the host. So just adding the hostname to /etc/hosts should do the trick I guess... or just using 127.0.0.1? Or the actual docker image id

rbren commented 6 months ago

Hey all--we've added a troubleshooting doc for this issue: https://github.com/OpenDevin/OpenDevin/blob/main/docs/guides/Troubleshooting.md#unable-to-connect-to-ssh-box

If there are any Workarounds you've found that are missing there, please open a PR to add them!

dagelf commented 6 months ago

So it seems there are multiple issues.

  1. The actual port on the ssh container is different. Might be because I ran the docker image twice. --rm in the commandline of the spawning code can fix that.
  2. The hostname doesn't exist on all machines. Refer to the image by its id.

Will try do a PR...

Mike-FreeAI commented 6 months ago

– - devin imcoming - -

PierrunoYT commented 6 months ago

Investigation Report for Issue 1156

Summary

Issue 1156 involves a critical bug related to pexpect/ssh when running Docker on WSL, marked with the labels 'bug' and 'severity:critical'. The issue manifests as a failure to establish an SSH connection within the Docker container used by the OpenDevin project.

Steps Taken

Current Status

The Docker container has been restarted, and the SSH service should now be running with the configuration set to allow password authentication. A new attempt to establish an SSH connection is needed to verify if the issue is resolved.

Next Steps

Challenges Encountered

Additional Notes

Mike-FreeAI commented 6 months ago

@PierrunoYT aka DEVIN OMG

PierrunoYT commented 6 months ago

It's slow as hell but it works.

dagelf commented 6 months ago

So adding this fixes it on Ubuntu at least, pretty sure it will resolve WSL too: --add-host host.docker.internal=host-gateway

dagelf commented 6 months ago

It's slow as hell but it works.

That's not slow...... but it should've tried more basic things first, like reading the logs, and checking local IP's and doing reachability checks, and searching existing issues.

Was that run on gpt3.5-turbo?

Mike-FreeAI commented 6 months ago

if you see this

It's slow as hell but it works.

That's not slow...... but it should've tried more basic things first, like reading the logs, and checking local IP's and doing reachability checks, and searching existing issues.

Was that run on gpt3.5-turbo?

devin wrote that

Mike-FreeAI commented 6 months ago

Thank you for the mention. I'm currently working on the issue and will keep you updated on the progress.

are you really devin? if so starcone of my github repos

Mike-FreeAI commented 6 months ago

are you really devin? if so star one of my github repos @PierrunoYT

Mike-FreeAI commented 6 months ago

reopened

rbren commented 6 months ago

🎉 Thanks @dagelf for (I hope) solving this one!

Tl;dr, you should add --add-host host.docker.internal=host-gateway to the docker run command.

rbren commented 6 months ago

@Mike-FreeAI does --add-host host.docker.internal=host-gateway not work for you? If that's the case I'll reopen

PierrunoYT commented 6 months ago

@Mike-FreeAI does --add-host host.docker.internal=host-gateway not work for you? If that's the case I'll reopen

We tried to fix the issue with Devin

msl2246 commented 6 months ago

i'm using ubuntu 22.04 (not a WSL2) getting same error

# Your OpenAI API key, or any other LLM API key
#export LLM_API_KEY="sk-..."
export LLM_API_KEY="sk-"
export LLM_MODEL="groq/llama3-70b-8192"
#export LLM_BASE_URL="https://api.groq.com/openai/v1"

# The directory you want OpenDevin to modify. MUST be an absolute path!
export WORKSPACE_BASE=/opt/workspace

docker run \
    -e LLM_API_KEY \
    -e LLM_MODEL \
    -e WORKSPACE_MOUNT_PATH=/opt/workspace \
    -v /opt/workspace:/opt/workspace_base \
    -v /var/run/docker.sock:/var/run/docker.sock \
    --add-host host.docker.internal=host-gateway \
    -p 3000:3000 \
    ghcr.io/opendevin/opendevin:0.3.1
(base) root@server:~# ./opendevin.sh 
INFO:     Started server process [1]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:3000 (Press CTRL+C to quit)
INFO:     192.168.1.124:51191 - "GET / HTTP/1.1" 307 Temporary Redirect
INFO:     192.168.1.124:51191 - "GET /api/refresh-files HTTP/1.1" 200 OK
INFO:     192.168.1.124:51191 - "GET /api/litellm-models HTTP/1.1" 200 OK
INFO:     192.168.1.124:51192 - "GET /api/messages/total HTTP/1.1" 200 OK
INFO:     192.168.1.124:51192 - "GET /api/agents HTTP/1.1" 404 Not Found
INFO:     ('192.168.1.124', 51195) - "WebSocket /ws?token=e*******" [accepted]
INFO:     connection open
Starting loop_recv for sid: 4da6f07b-ee2d-41fb-a1b0-3f3f21c1f3fb
INFO:     192.168.1.124:51192 - "GET /api/messages/total HTTP/1.1" 200 OK
18:14:11 - opendevin:INFO: ssh_box.py:271 - Container stopped
18:14:11 - opendevin:WARNING: ssh_box.py:283 - Using port forwarding for Mac OS. Server started by OpenDevin will not be accessible from the host machine at the moment. See https://github.com/OpenDevin/OpenDevin/issues/897 for more information.
18:14:11 - opendevin:INFO: ssh_box.py:309 - Container started
18:14:12 - opendevin:INFO: ssh_box.py:326 - waiting for container to start: 1, container status: exited
18:14:12 - opendevin:INFO: ssh_box.py:318 - container exited
18:14:12 - opendevin:INFO: ssh_box.py:319 - container logs:
18:14:12 - opendevin:INFO: ssh_box.py:320 - b'Missing privilege separation directory: /run/sshd\r\n'
18:14:12 - opendevin:ERROR: agent.py:127 - Error creating controller: Failed to start container
Traceback (most recent call last):
  File "/app/opendevin/server/agent/agent.py", line 118, in create_controller
    self.controller = AgentController(
                      ^^^^^^^^^^^^^^^^
  File "/app/opendevin/controller/agent_controller.py", line 51, in __init__
    self.command_manager = CommandManager(self.id, container_image)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/opendevin/controller/command_manager.py", line 26, in __init__
    self.shell = DockerSSHBox(
                 ^^^^^^^^^^^^^
  File "/app/opendevin/sandbox/ssh_box.py", line 87, in __init__
    self.restart_docker_container()
  File "/app/opendevin/sandbox/ssh_box.py", line 331, in restart_docker_container
    raise Exception('Failed to start container')
Exception: Failed to start container
(base) root@server:~# uname -a
Linux server 6.5.0-28-generic #29~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Apr  4 14:39:20 UTC 2 x86_64 x86_64 x86_64 GNU/Linux 

well, idk it's relevant i'm using sshd(port 22 are already opened, by opensshd)

image

rbren commented 5 months ago

Reopening this, as it appears to still be affecting some folks

PierrunoYT commented 5 months ago

pierruno@Pierruno:/mnt/c/Users/pierr/OpenDevin$ docker run \ -e LLM_API_KEY \ -e WORKSPACE_MOUNT_PATH=$WORKSPACE_DIR \ -v $WORKSPACE_DIR:/opt/workspace_base \ -v /var/run/docker.sock:/var/run/docker.sock \ -p 3000:3000 \ ghcr.io/opendevin/opendevin:0.4.0 Unable to find image 'ghcr.io/opendevin/opendevin:0.4.0' locally 0.4.0: Pulling from opendevin/opendevin b0a0cf830b12: Pull complete 72914424168c: Pull complete 80818bc858ed: Pull complete 805c2b19c211: Pull complete 7a89e8daeeae: Pull complete 5978226c46e8: Pull complete 18a065431faa: Pull complete 4a54321ea818: Pull complete ae971a861ecc: Pull complete 53965936ef14: Pull complete f9e7f90d3cb9: Pull complete f6726e7a8de0: Pull complete 6d7f23ac30e6: Pull complete b45b748e127a: Pull complete Digest: sha256:c3b990fc861746feeb3f026a951174f28861909d6f6c8bff5a6e5abdf21481e2 Status: Downloaded newer image for ghcr.io/opendevin/opendevin:0.4.0 INFO: Started server process [1] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:3000 (Press CTRL+C to quit) INFO: 172.17.0.1:50460 - "GET / HTTP/1.1" 307 Temporary Redirect INFO: 172.17.0.1:50460 - "GET /index.html HTTP/1.1" 200 OK INFO: 172.17.0.1:50460 - "GET /assets/index-D59teWsw.js HTTP/1.1" 200 OK INFO: 172.17.0.1:50462 - "GET /assets/index-CZQzs2DR.css HTTP/1.1" 200 OK INFO: ('172.17.0.1', 50474) - "WebSocket /ws?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzaWQiOiJiMWU1ZDM1My05MDM1LTRiYTEtOGEwMC04NGZmNDU0ZWMxYTEifQ.VHFX1AwnLJprhuTP_CHGpOpUBZNlruNT6Guzt1y2G9k" [accepted] INFO: connection open Starting loop_recv for sid: b1e5d353-9035-4ba1-8a00-84ff454ec1a1 INFO: 172.17.0.1:50462 - "GET /locales/de/translation.json HTTP/1.1" 200 OK INFO: 172.17.0.1:50460 - "GET /locales/en/translation.json HTTP/1.1" 200 OK INFO: 172.17.0.1:50462 - "GET /favicon-32x32.png HTTP/1.1" 200 OK INFO: 172.17.0.1:50460 - "GET /apple-touch-icon.png HTTP/1.1" 200 OK 18:30:10 - opendevin:INFO: agent.py:144 - Creating agent MonologueAgent using LLM gpt-4-0125-preview 18:30:10 - opendevin:INFO: llm.py:51 - Initializing LLM with model: gpt-4-0125-preview 18:30:10 - opendevin:INFO: ssh_box.py:353 - Container stopped 18:30:10 - opendevin:INFO: ssh_box.py:373 - Mounting workspace directory: /mnt/c/Users/pierr/OpenDevin/workspace 18:30:33 - opendevin:INFO: ssh_box.py:396 - Container started 18:30:34 - opendevin:INFO: ssh_box.py:413 - waiting for container to start: 1, container status: running 18:30:34 - opendevin:INFO: ssh_box.py:178 - Connecting to root@host.docker.internal via ssh. If you encounter any issues, you can try ssh -v -p 45061 root@host.docker.internal with the password '4b113e4d-8215-443b-acd7-f11dc1caa40b' and report the issue on GitHub. 18:30:34 - opendevin:ERROR: agent.py:155 - Error creating controller: Could not establish connection to host Traceback (most recent call last): File "/app/opendevin/server/agent/agent.py", line 147, in create_controller self.controller = AgentController( ^^^^^^^^^^^^^^^^ File "/app/opendevin/controller/agent_controller.py", line 57, in init self.action_manager = ActionManager(self.id) ^^^^^^^^^^^^^^^^^^^^^^ File "/app/opendevin/controller/action_manager.py", line 33, in init self.sandbox = DockerSSHBox( ^^^^^^^^^^^^^ File "/app/opendevin/sandbox/docker/ssh_box.py", line 91, in init self.start_ssh_session() File "/app/opendevin/sandbox/docker/ssh_box.py", line 181, in start_ssh_session self.ssh.login(hostname, username, self._ssh_password, File "/app/.venv/lib/python3.12/site-packages/pexpect/pxssh.py", line 424, in login raise ExceptionPxssh('Could not establish connection to host') pexpect.pxssh.ExceptionPxssh: Could not establish connection to host INFO: 172.17.0.1:50462 - "GET /api/litellm-models HTTP/1.1" 200 OK INFO: 172.17.0.1:50482 - "GET /api/messages/total HTTP/1.1" 200 OK INFO: 172.17.0.1:50494 - "GET /sw.js HTTP/1.1" 404 Not Found INFO: 172.17.0.1:50508 - "GET /workbox-c06b064f.js HTTP/1.1" 404 Not Found INFO: 172.17.0.1:50460 - "GET /api/refresh-files HTTP/1.1" 200 OK INFO: 172.17.0.1:50460 - "GET /api/agents HTTP/1.1" 200 OK INFO: 172.17.0.1:50460 - "GET /sw.js HTTP/1.1" 404 Not Found INFO: 172.17.0.1:50462 - "GET /workbox-c06b064f.js HTTP/1.1" 404 Not Found INFO: 172.17.0.1:50460 - "DELETE /api/messages HTTP/1.1" 200 OK INFO: 172.17.0.1:50462 - "GET /workbox-c06b064f.js HTTP/1.1" 404 Not Found INFO: 172.17.0.1:50460 - "GET /sw.js HTTP/1.1" 404 Not Found

SmartManoj commented 5 months ago

you can try ssh -v -p 45061 root@host.docker.internal with the password '4b113e4d-8215-443b-acd7-f11dc1caa40b' and report the issue on GitHub.

Did you try?

dagelf commented 5 months ago

There's two different errors here: The original issue here:

opendevin:ERROR: agent.py:155 - Error creating controller: Could not establish connection to host
Traceback (most recent call last):

This one is fixed by --add-host host.docker.internal=host-gateway. Nobody has yet proven otherwise. @PierrunoYT you didn't add this... that's why it's not working. (It looks like)

opendevin:INFO: ssh_box.py:320 - b'Missing privilege separation directory: /run/sshd\r\n'
opendevin:ERROR: agent.py:127 - Error creating controller: Failed to start container
Traceback (most recent call last):

That happens when there is no /run/sshd directory when /usr/sbin/sshd is run... seems to be a containerization or container template issue. (Or permissions or disk full?)

@msl2246 This is a separate issue. I guess seeing as that the final error is the same we can work on this issue here. Does anyone know what the ssh image is created or pulled from, and how to test it separately?

Maybe an mkdir /run/sshd can be added in the ssh container, just to be sure?

enyst commented 5 months ago

Maybe an mkdir /run/sshd can be added in the ssh container, just to be sure?

It has been added, indeed. I believe version 0.4.0, the newest released version, includes it.

enyst commented 5 months ago

@msl2246 please update to 0.4.0

@PierrunoYT

pierruno@Pierruno:/mnt/c/Users/pierr/OpenDevin$ docker run -e LLM_API_KEY -e WORKSPACE_MOUNT_PATH=$WORKSPACE_DIR -v $WORKSPACE_DIR:/opt/workspace_base -v /var/run/docker.sock:/var/run/docker.sock -p 3000:3000 ghcr.io/opendevin/opendevin:0.4.0

Please add --add-host host.docker.internal=host-gateway \ to the command. Double-check the README for the whole command.

arose26 commented 5 months ago

@wmitnaj that's helpful, I'm surprised to hear that docker on WSL has this problem

Setting -e SANDBOX_TYPE=exec may fix the issue for now

On WSL2, this fixes another issue where issuing internet requests from within a python program fails.

neubig commented 4 months ago

This hasn't been updated for a month, so I guess this is probably fixed? I'll close it for now, but we can re-open new ones.

cian0 commented 3 months ago

I have a fresh install with docker, I'm getting the same error below

my command:

docker run -it \
    --pull=always \
    -e LLM_API_KEY \
    -e LLM_MODEL \
    -e SANDBOX_USER_ID=$(id -u) \
    -e WORKSPACE_MOUNT_PATH=$WORKSPACE_BASE \
    -v $WORKSPACE_BASE:/opt/workspace_base \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -p 3000:3000 \
    --add-host host.docker.internal:host-gateway \
    --name opendevin-app-$(date +%Y%m%d%H%M%S) \
    ghcr.io/opendevin/opendevin

The error:

06:57:30 - opendevin:INFO: ssh_box.py:741 - Container started
06:57:31 - opendevin:INFO: ssh_box.py:757 - waiting for container to start: 1, container status: running
06:57:31 - opendevin:INFO: ssh_box.py:426 - Connecting to SSH session...
06:57:31 - opendevin:INFO: ssh_box.py:428 - You can debug the SSH connection by running: `ssh -v -p 34161 opendevin@host.docker.internal` using the password '69264b31-3d57-49c2-bf6c-e4b5fe4e2629'
06:57:44 - opendevin:ERROR: ssh_box.py:434 - Failed to login to SSH session, retrying...
06:57:49 - opendevin:INFO: ssh_box.py:426 - Connecting to SSH session...
06:57:49 - opendevin:INFO: ssh_box.py:428 - You can debug the SSH connection by running: `ssh -v -p 34161 opendevin@host.docker.internal` using the password '69264b31-3d57-49c2-bf6c-e4b5fe4e2629'
06:58:02 - opendevin:ERROR: ssh_box.py:434 - Failed to login to SSH session, retrying...
06:58:07 - opendevin:INFO: ssh_box.py:426 - Connecting to SSH session...
06:58:07 - opendevin:INFO: ssh_box.py:428 - You can debug the SSH connection by running: `ssh -v -p 34161 opendevin@host.docker.internal` using the password '69264b31-3d57-49c2-bf6c-e4b5fe4e2629'
06:58:20 - opendevin:ERROR: ssh_box.py:434 - Failed to login to SSH session, retrying...
06:58:25 - opendevin:INFO: ssh_box.py:426 - Connecting to SSH session...
06:58:25 - opendevin:INFO: ssh_box.py:428 - You can debug the SSH connection by running: `ssh -v -p 34161 opendevin@host.docker.internal` using the password '69264b31-3d57-49c2-bf6c-e4b5fe4e2629'
06:58:37 - opendevin:ERROR: ssh_box.py:434 - Failed to login to SSH session, retrying...
06:58:42 - opendevin:INFO: ssh_box.py:426 - Connecting to SSH session...
06:58:42 - opendevin:INFO: ssh_box.py:428 - You can debug the SSH connection by running: `ssh -v -p 34161 opendevin@host.docker.internal` using the password '69264b31-3d57-49c2-bf6c-e4b5fe4e2629'
06:58:55 - opendevin:ERROR: ssh_box.py:434 - Failed to login to SSH session, retrying...
06:58:55 - opendevin:ERROR: session.py:73 - Error creating controller: RetryError[<Future at 0x75b89a892fc0 state=finished raised ExceptionPxssh>]
Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 478, in __call__
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/app/opendevin/runtime/docker/ssh_box.py", line 437, in __ssh_login
    raise e
  File "/app/opendevin/runtime/docker/ssh_box.py", line 431, in __ssh_login
    self.ssh.login(hostname, username, self._ssh_password, port=self._ssh_port)
  File "/app/.venv/lib/python3.12/site-packages/pexpect/pxssh.py", line 464, in login
    raise ExceptionPxssh('could not synchronize with original prompt')
pexpect.pxssh.ExceptionPxssh: could not synchronize with original prompt

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/opendevin/server/session/session.py", line 71, in _initialize_agent
    await self.agent_session.start(data)
  File "/app/opendevin/server/session/agent.py", line 46, in start
    await self._create_runtime()
  File "/app/opendevin/server/session/agent.py", line 65, in _create_runtime
    self.runtime = ServerRuntime(self.event_stream, self.sid)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/opendevin/runtime/server/runtime.py", line 35, in __init__
    super().__init__(event_stream, sid, sandbox)
  File "/app/opendevin/runtime/runtime.py", line 70, in __init__
    self.sandbox = create_sandbox(sid, config.sandbox.box_type)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/opendevin/runtime/runtime.py", line 44, in create_sandbox
    return DockerSSHBox(sid=sid)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/opendevin/runtime/docker/ssh_box.py", line 285, in __init__
    raise e
  File "/app/opendevin/runtime/docker/ssh_box.py", line 282, in __init__
    self.start_ssh_session()
  File "/app/opendevin/runtime/docker/ssh_box.py", line 440, in start_ssh_session
    self.__ssh_login()
  File "/app/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 336, in wrapped_f
    return copy(f, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 475, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 376, in iter
    result = action(retry_state)
             ^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 419, in exc_check
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x75b89a892fc0 state=finished raised ExceptionPxssh>]

When I try to login to SSH as prompted:

ssh -v -p 34161 opendevin@host.docker.internal
OpenSSH_8.9p1 Ubuntu-3ubuntu0.10, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
ssh: Could not resolve hostname host.docker.internal: Name or service not known