All-Hands-AI / OpenHands

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

Failed to login to SSH session - Ubuntu (not WSL) #2911

Open cian0 opened 2 months ago

cian0 commented 2 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

Originally posted by @cian0 in https://github.com/OpenDevin/OpenDevin/issues/1156#issuecomment-2226800657

SmartManoj commented 2 months ago

Could you check if the sandbox container is running in Docker Desktop and log in using ssh -v -p 34161 opendevin@localhost if so?

Related SO Post: pxssh error 'could not synchronize with original prompt' Related issue: https://github.com/pexpect/pexpect/issues/7

RaunakChhatwal commented 1 month ago

Same issue in NixOS. I can log into the opendevin-sandbox container using ssh from the host but not from inside the opendevin-app container.

SmartManoj commented 1 month ago

Could you please provide the logs?

RaunakChhatwal commented 1 month ago

This was a firewall issue. I resolved this by adding docker0 to networking.firewalls.trustedInterfaces. @cian0 Claude tells me sudo ufw allow in on docker0 and sudo ufw reload is the ubuntu equivalent to this.

budihartono commented 1 month ago

This was a firewall issue. I resolved this by adding docker0 to networking.firewalls.trustedInterfaces. @cian0 Claude tells me sudo ufw allow in on docker0 and sudo ufw reload is the ubuntu equivalent to this.

I can confirm this solution works on my server as well. Thank you!

alimsyed commented 1 month ago

This was a firewall issue. I resolved this by adding docker0 to networking.firewalls.trustedInterfaces. @cian0 Claude tells me sudo ufw allow in on docker0 and sudo ufw reload is the ubuntu equivalent to this.

This worked for me too, thanks for the hint. I used IPTABLES to fix this.

github-actions[bot] commented 3 days ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.