Default for sandbox to use the host network (#1334)

* default to use host network

* make host network as default
This commit is contained in:
Xingyao Wang
2024-04-25 05:48:11 +08:00
committed by GitHub
parent 1e95fa435d
commit fde0392457
3 changed files with 12 additions and 7 deletions

View File

@@ -32,7 +32,7 @@ FROM python:3.12-slim as runtime
WORKDIR /app
ENV RUN_AS_DEVIN=false
ENV USE_HOST_NETWORK=false
ENV USE_HOST_NETWORK=true
ENV SSH_HOSTNAME=host.docker.internal
ENV WORKSPACE_BASE=/opt/workspace_base
RUN mkdir -p $WORKSPACE_BASE

View File

@@ -2,6 +2,7 @@ import os
import argparse
import toml
import pathlib
import platform
from dotenv import load_dotenv
from opendevin.schema import ConfigType
@@ -36,7 +37,7 @@ DEFAULT_CONFIG: dict = {
ConfigType.AGENT: 'MonologueAgent',
ConfigType.E2B_API_KEY: '',
ConfigType.SANDBOX_TYPE: 'ssh', # Can be 'ssh', 'exec', or 'e2b'
ConfigType.USE_HOST_NETWORK: 'false',
ConfigType.USE_HOST_NETWORK: 'true',
ConfigType.SSH_HOSTNAME: 'localhost',
ConfigType.DISABLE_COLOR: 'false',
}
@@ -134,6 +135,14 @@ def finalize_config():
parts = config[ConfigType.WORKSPACE_MOUNT_REWRITE].split(':')
config[ConfigType.WORKSPACE_MOUNT_PATH] = base.replace(parts[0], parts[1])
USE_HOST_NETWORK = config[ConfigType.USE_HOST_NETWORK].lower() != 'false'
if USE_HOST_NETWORK and platform.system() == 'Darwin':
logger.warning(
'Please upgrade to Docker Desktop 4.29.0 or later to use host network mode on macOS. '
'See https://github.com/docker/roadmap/issues/238#issuecomment-2044688144 for more information.'
)
config[ConfigType.USE_HOST_NETWORK] = USE_HOST_NETWORK
if config.get(ConfigType.WORKSPACE_MOUNT_PATH) is None:
config[ConfigType.WORKSPACE_MOUNT_PATH] = config.get(ConfigType.WORKSPACE_BASE)

View File

@@ -1,6 +1,5 @@
import atexit
import os
import platform
import sys
import time
import uuid
@@ -31,10 +30,7 @@ CONTAINER_IMAGE = config.get(ConfigType.SANDBOX_CONTAINER_IMAGE)
SSH_HOSTNAME = config.get(ConfigType.SSH_HOSTNAME)
USE_HOST_NETWORK = platform.system() == 'Linux'
if config.get(ConfigType.USE_HOST_NETWORK) is not None:
USE_HOST_NETWORK = config.get(
ConfigType.USE_HOST_NETWORK).lower() != 'false'
USE_HOST_NETWORK = config.get(ConfigType.USE_HOST_NETWORK)
# FIXME: On some containers, the devin user doesn't have enough permission, e.g. to install packages
# How do we make this more flexible?