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]
fixed broken stuff after merge
Talor Abramovich6ab8915851c7
diff --git a/config/default_ctf.yaml b/config/default_ctf.yamlindex 34c2117e..d8e4fafd 100644--- a/config/default_ctf.yaml+++ b/config/default_ctf.yaml@@ -34,6 +34,8 @@ instance_template: |-{description}Files included in the challenge: {files}+ {server_description}+INSTRUCTIONS:Now, you're going to solve this challenge on your own. Your terminal session has started and you're in the challenge's root directory. You can use any bash commands or the special interface to help you.Solve the challenge, executing any commands you need and writing any code that may be helpful. You can also install new software in the container using `sudo apt-get install`, or Python packages with `pip install`.diff --git a/config/environment_setup/py310_ctf.yaml b/config/environment_setup/py310_ctf.yamlindex b1bc786e..f72049d0 100644--- a/config/environment_setup/py310_ctf.yaml+++ b/config/environment_setup/py310_ctf.yaml@@ -1,4 +1,4 @@python: '3.10'# Use uv pip for speedup, but fallback to classic pip if we fail# Upgrade pip to avoid https://stackoverflow.com/a/73779542/-install: 'uv pip install pwntools ipython gmpy2 pycryptodome mpmath sympy ruff'+install: 'uv pip install pwntools ipython pycryptodome mpmath sympy ruff'diff --git a/run.py b/run.pyindex 1a110ca4..9373c433 100644--- a/run.py+++ b/run.py@@ -371,6 +371,7 @@ class Main:setup_args["files"] = challenge["files"]setup_args["box"] = challenge.get("server_name")setup_args["port"] = challenge.get("port")+ setup_args["server_description"] = challenge.get("server_description")info, trajectory = self.agent.run(setup_args=setup_args,env=self.env,diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex bef0836d..359db915 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -229,10 +229,10 @@ class SWEEnv(gym.Env):for hook in self.hooks:hook.on_copy_repo_started(repo_type=self.record["repo_type"], repo_path=self.record["repo"])if self.record["repo_type"] == "local":- if "files" in self.record:+ if "challenge" in self.record:self.communicate_with_handling(input=f"mkdir {self._repo_name}",error_msg=f"Failed to create {self._repo_name} in container")- for file_name in self.record["files"]:+ for file_name in self.record["challenge"]["files"]:self.logger.debug(f"Copying file {file_name} to container")copy_anything_to_container(self.container_obj,@@ -835,6 +835,10 @@ class SWEEnv(gym.Env):Returns:output: output from container"""+ if self.challenge is not None and input.startswith("git"):+ msg = "Skipping git commands for CTF challenges"+ self.logger.debug(msg)+ return msglogs = self.communicate(input, timeout_duration=timeout_duration)if self.returncode != 0:self.logger.error(f"{error_msg}: {logs}")diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.pyindex 3a15bae9..39c05cfe 100644--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@ -237,7 +237,7 @@ def read_with_timeout_experimental(container: subprocess.Popen, timeout_durationbreakif data:buffer += data- if PROCESS_DONE_MARKER_START in buffer.decode():+ if PROCESS_DONE_MARKER_START in buffer.decode('utf-8', errors='backslashreplace').replace('\r\n', '\n'):breaktime.sleep(0.01) # Prevents CPU hogging@@ -608,6 +608,15 @@ class InstanceBuilder:)self.args["instance_id"] = f"{owner}__{repo}-i{issue_number}"self.args["problem_statement_source"] = "online"++ def set_server_description(self, server_name: str | None, port: int | None) -> None:+ if server_name is None or port is None:+ self.args["challenge"]["server_description"] = ""+ return+ if self.args["challenge"]["category"] in {"web", "misc"} and self.args["challenge"].get("proto") != "nc":+ self.args["challenge"]["server_description"] = f"The challenge web server is running on `{server_name}` port `{port}` and you can access it from within the container environment using `curl http://{server_name}:{port}`."+ else:+ self.args["challenge"]["server_description"] = f"The challenge web server is running on `{server_name}` port `{port}` and you can access it from within the container environment using `nc {server_name}:{port}`."def set_problem_statement_from_challenge_json(self, file_path: str) -> str:challenge = json.loads(Path(file_path).read_text())@@ -620,6 +629,7 @@ class InstanceBuilder:self.args["challenge"]["docker_compose"] = (Path(file_path).parent / "docker-compose.yml")self.args["challenge"]["port"] = challenge.get("internal_port")self.args["challenge"]["server_name"] = challenge.get("box")+ self.set_server_description(self.args["challenge"]["server_name"], self.args["challenge"]["port"])self.set_problem_statement_from_text(f"{challenge['name']} {challenge['description']}")def set_problem_statement_from_file(self, file_path: str):