Skip to content

Commit

Permalink
set-up random user password and only allow localhost connection for s…
Browse files Browse the repository at this point in the history
…andbox
  • Loading branch information
xingyaoww committed Apr 7, 2024
1 parent fb04728 commit dd87df9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions opendevin/sandbox/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def __init__(

if not self.is_container_running():
self.restart_docker_container()
# set up random user password
self._ssh_password = str(uuid.uuid4())
if RUN_AS_DEVIN:
self.setup_devin_user()
self.start_ssh_session()
Expand All @@ -147,7 +149,8 @@ def setup_devin_user(self):
workdir='/workspace',
)
exit_code, logs = self.container.exec_run(
['/bin/bash', '-c', "echo 'opendevin:opendevin' | chpasswd"],
['/bin/bash', '-c',
f"echo 'opendevin:{self._ssh_password}' | chpasswd"],
workdir='/workspace',
)
exit_code, logs = self.container.exec_run(
Expand All @@ -160,8 +163,7 @@ def start_ssh_session(self):
self.ssh = pxssh.pxssh()
hostname = 'localhost'
username = 'opendevin'
password = 'opendevin'
self.ssh.login(hostname, username, password, port=2222)
self.ssh.login(hostname, username, self._ssh_password, port=2222)

# Fix: https://github.com/pexpect/pexpect/issues/669
self.ssh.sendline("bind 'set enable-bracketed-paste off'")
Expand Down Expand Up @@ -292,7 +294,8 @@ def restart_docker_container(self):
# start the container
self.container = docker_client.containers.run(
self.container_image,
command='/usr/sbin/sshd -D -p 2222',
# only allow connections from localhost
command="/usr/sbin/sshd -D -p 2222 -o 'ListenAddress=127.0.0.1'",
network_mode='host',
working_dir='/workspace',
name=self.container_name,
Expand Down

0 comments on commit dd87df9

Please sign in to comment.