SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
attaching relevant network interface
Talor Abramovich961b23a9f746
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex d04a948f..42db4328 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -29,6 +29,7 @@ from sweagent.environment.utils import (PROCESS_DONE_MARKER_END,PROCESS_DONE_MARKER_START,InvalidGithubURL,+ attach_network_interface_to_container,copy_anything_to_container,copy_file_to_container,format_trajectory_markdown,@@ -337,6 +338,9 @@ class SWEEnv(gym.Env):else:self.logger.info(f"Cached image {cached_image} not found, rebuilding task environment...")+ # Init docker network+ self._init_docker_network()+# Clone repository if not already clonedself.communicate(input="cd /")folders = self.communicate(input="ls").split("\n")@@ -599,6 +603,14 @@ class SWEEnv(gym.Env):image_name_sanitized = image_name_sanitized.replace(":", "-")return f"{image_name_sanitized}-{hash_object.hexdigest()[:10]}"+ def _init_docker_network(self) -> None:+ """+ Add the "ctfnet" network interface for all the containers used for CTF challenges+ """+ assert self.container_name is not None+ if self.challenge is not None:+ attach_network_interface_to_container(self.container_name)+def _init_docker_compose(self) -> None:"""Handles docker compose initialization for challenge with docker compose file.diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.pyindex 13ebe0dd..27d9e27b 100644--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@ -288,6 +288,29 @@ def terminate_docker_compose(docker_compose_path: Path) -> None:logger.error(f"Unexpected compose termination error: {error}")+def attach_network_interface_to_container(container_name: str) -> None:+ cmd = [+ "docker",+ "network",+ "connect",+ "ctfnet",+ container_name,+ ]+ logger.debug("Attaching NIC to container with command: %s", shlex.join(cmd))+ compose = subprocess.Popen(+ cmd,+ stdin=PIPE,+ stdout=PIPE,+ stderr=STDOUT,+ text=True,+ bufsize=1, # line buffered+ )+ _, error = compose.communicate(timeout=DOCKER_START_UP_DELAY)+ if error:+ logger.error(f"Unexpected compose setup error: {error}")+ raise RuntimeError(error)++def get_docker_compose(docker_compose_path: Path) -> Path:startup_cmd = ["docker",