π OpenHands: AI-Driven Development
allow interaction with local box (#1429)
Xingyao Wanga7e42ff0a3fd
diff --git a/opendevin/sandbox/docker/local_box.py b/opendevin/sandbox/docker/local_box.pyindex 4d84fdfb9f..26800e0df9 100644--- a/opendevin/sandbox/docker/local_box.py+++ b/opendevin/sandbox/docker/local_box.py@@ -1,10 +1,12 @@import subprocessimport atexitimport os+import sysfrom typing import Tuple, Dictfrom opendevin.sandbox.sandbox import Sandboxfrom opendevin.sandbox.process import Processfrom opendevin.sandbox.docker.process import DockerProcess+from opendevin.logger import opendevin_logger as loggerfrom opendevin import configfrom opendevin.schema.config import ConfigType@@ -96,3 +98,37 @@ class LocalBox(Sandbox):def cleanup(self):self.close()+++if __name__ == '__main__':++ local_box = LocalBox()+ bg_cmd = local_box.execute_in_background(+ "while true; do echo 'dot ' && sleep 10; done"+ )++ sys.stdout.flush()+ try:+ while True:+ try:+ user_input = input('>>> ')+ except EOFError:+ logger.info('Exiting...')+ break+ if user_input.lower() == 'exit':+ logger.info('Exiting...')+ break+ if user_input.lower() == 'kill':+ local_box.kill_background(bg_cmd.pid)+ logger.info('Background process killed')+ continue+ exit_code, output = local_box.execute(user_input)+ logger.info('exit code: %d', exit_code)+ logger.info(output)+ if bg_cmd.pid in local_box.background_commands:+ logs = local_box.read_logs(bg_cmd.pid)+ logger.info('background logs: %s', logs)+ sys.stdout.flush()+ except KeyboardInterrupt:+ logger.info('Exiting...')+ local_box.close()