* Remove global config from memory * Remove runtime global config * Remove from storage * Remove global config * Fix event stream tests * Fix sandbox issue * Change config * Removed transferred tests * Add swe env box * Fixes on testing * Fixed some tests * Merge with stashed changes * Fix typing * Fix ipython test * Revive function * Make temp_dir fixture * Remove test to avoid circular import * fix eventstream filestore for test_runtime * fix parse arg issue that cause integration test to fail * support swebench pull from custom namespace * add back simple tests for runtime * move multi-line bash tests to test_runtime; support multi-line bash for esruntime; * add testcase to handle PS2 prompt * use bashlex for bash parsing to handle multi-line commands; add testcases for multi-line commands * revert ghcr runtime change * Apply stash * fix run as other user; make test async; * fix test runtime for run as od * add run-as-devin to all the runtime tests * handle the case when username is root * move all run-as-devin tests from sandbox; only tests a few cases on different user to save time; * move over multi-line echo related tests to test_runtime * fix user-specific jupyter by fixing the pypoetry virtualenv folder * make plugin's init async; chdir at initialization of jupyter plugin; move ipy simple testcase to test runtime; * support agentskills import in move tests for jupyter pwd tests; overload `add_env_vars` for EventStreamRuntime to update env var also in Jupyter; make agentskills read env var lazily, in case env var is updated; * fix ServerRuntime agentskills issue * move agnostic image test to test_runtime * merge runtime tests in CI * fix enable auto lint as env var * update warning message * update warning message * test for different container images * change parsing output as debug * add exception handling for update_pwd_decorator * fix unit test indentation * add plugins as default input to Runtime class; remove init_sandbox_plugins; implement add_env_var (include jupyter) in the base class; * fix server runtime auto lint * Revert "add exception handling for update_pwd_decorator" This reverts commit2b668b1506. * tries to print debugging info for agentskills * explictly setting uid (try fix permission issue) * Revert "tries to print debugging info for agentskills" This reverts commit8be4c86756. * set sandbox user id during testing to hopefully fix the permission issue * add browser tools for server runtime * try to debug for old pwd * update debug cmd * only test agnostic runtime when TEST_RUNTIME is Server * fix temp dir mkdir * load TEST_RUNTIME at the beginning * remove ipython tests * only log to file when DEBUG * default logging to project root * temporarily remove log to file * fix LLM logger dir * fix logger * make set pwd an optional aux action * fix prev pwd * fix infinity recursion * simplify * do not import the whole od library to avoid logger folder by jupyter * fix browsing * increase timeout * attempt to fix agentskills yet again * clean up in testcases, since CI maybe run as non-root * add _cause attribute for event.id * remove parent * add a bunch of debugging statement again for CI :( * fix temp_dir fixture * change all temp dir to follow pytest's tmp_path_factory * remove extra bracket * clean up error printing a bit * jupyter chdir to self.config.workspace_mount_path_in_sandbox on initialization * jupyter chdir to self.config.workspace_mount_path_in_sandbox on initialization * add typing for tmp dir fixture * clear the directory before running the test to avoid weird CI temp dir * remove agnostic test case for server runtime * Revert "remove agnostic test case for server runtime" This reverts commit30e2181c3f. * disable agnostic tests in CI * fix test --------- Co-authored-by: Graham Neubig <neubig@gmail.com>
OpenDevin Runtime
This README provides an overview of the OpenDevin Runtime, a crucial component of the OpenDevin system. It covers two main aspects:
- How the Runtime Image is Built: Explains the layered approach to creating Docker images for both production and development environments.
- How the Runtime Client Works: Details the functionality and architecture of the Runtime Client, which executes actions within the Docker sandbox.
The following sections dive deeper into these topics, providing a comprehensive understanding of the OpenDevin Runtime system.
Architecture Diagram
+-------------------+ +-------------------+
| OpenDevin | | Docker Host |
| Backend | | |
| | | +-------------+ |
| +-------------+ | | | Runtime | |
| | EventStream | | | | Container | |
| | Runtime |<-|-----|->| | |
| +-------------+ | | | +-------+ | |
| | | | |Runtime| | |
| | | | |Client | | |
| | | | +-------+ | |
| | | | | | |
| | | | +-------+ | |
| | | | |Plugins| | |
| | | | +-------+ | |
| | | +-------------+ |
+-------------------+ +-------------------+
This diagram illustrates the high-level architecture of the OpenDevin Runtime system:
- The OpenDevin Backend communicates with the Docker Host through the EventStreamRuntime.
- The Docker Host runs a Runtime Container, which includes:
- The Runtime Client: Handles incoming actions and generates observations.
- Plugins: Extend the functionality of the Runtime Client.
- The Runtime Client executes actions within the sandboxed environment of the Docker container.
This architecture ensures a secure and flexible environment for executing AI-driven development tasks, allowing OpenDevin to execute a wide range of actions safely and efficiently.
How the Runtime Image is Built
The OpenDevin runtime uses a layered approach for building Docker images:
-
Original Image:
ubuntu:22.04- This is the base image used for all subsequent layers.
-
Runtime Image:
od_runtime:od_v{OPENDEVIN_VERSION}_image_ubuntu__22.04
Example image name: od_runtime:od_v0.8.1_image_ubuntu__22.04
- Built from the stable release of OpenDevin.
- This is the primary runtime image that users will interact with.
- Created by copying all OpenDevin code into the original image and installing dependencies using Poetry.
- Dev Runtime Image:
od_runtime_dev:od_v{OPENDEVIN_VERSION}_image_ubuntu__22.04- Built from local source code for development purposes.
Build Process
Production Build (if environment variable SANDBOX_UPDATE_SOURCE_CODE is not set)
By default, when SANDBOX_UPDATE_SOURCE_CODE is unset OR set to false, the build process only needs to run once:
- The Runtime Image (
od_runtime:od_v{OPENDEVIN_VERSION}_image_ubuntu__22.04) is created by copying OpenDevin code into the original Ubuntu image and installing all dependencies. - This pre-built image is then used for running the OpenDevin environment.
Development Build (env var SANDBOX_UPDATE_SOURCE_CODE=True)
When developing or modifying code that runs inside the container, you can set env var SANDBOX_UPDATE_SOURCE_CODE=True to enable a more dynamic build process:
- Every time you run the code, the existing image will be updated with the latest changes.
- The Dev Runtime Image (
od_runtime_dev:od_v{OPENDEVIN_VERSION}_image_ubuntu__22.04) is rebuilt from the Runtime Image (od_runtime:od_v{OPENDEVIN_VERSION}_image_ubuntu__22.04). - Most dependencies are already installed in the Runtime Image, so this process mainly updates the code and any new dependencies.
- The rebuild process typically takes around 10 seconds, allowing for quick iterations during development.
This approach allows developers to easily test changes to the OpenDevin codebase, including modifications to files like client.py, without needing to rebuild the entire image from scratch each time.
How the Runtime Client Works
The Runtime Client is a crucial component of the OpenDevin system, responsible for executing actions within the Docker sandbox environment and producing observations. Here's an overview of its functionality:
-
Initialization:
- The
EventStreamRuntimeclass inruntime.pyinitializes the Docker container and sets up the runtime environment.
- The
-
Communication:
- The Runtime Client uses FastAPI to create a web server inside the Docker container.
- It listens for incoming action requests from the OpenDevin backend.
-
Action Execution:
- When an action is received, the Runtime Client processes it based on its type:
CmdRunAction: Executes shell commands using a pexpect-spawned bash shell.FileReadActionandFileWriteAction: Perform file operations within the sandbox.IPythonRunCellAction: Executes Python code in an IPython environment.BrowseURLActionandBrowseInteractiveAction: Handle web browsing tasks using a browser environment.
- When an action is received, the Runtime Client processes it based on its type:
-
Plugin System:
- The Runtime Client supports a plugin system for extending functionality.
- Plugins like JupyterPlugin can be loaded to provide additional features.
-
Observation Generation:
- After executing an action, the Runtime Client generates an appropriate observation.
- Observations include command outputs, file contents, error messages, etc.
-
Asynchronous Operation:
- The Runtime Client uses asyncio for avoid concurrent requests.
- It ensures that only one action is executed at a time using a semaphore.
-
Security:
- All actions are executed within the confined Docker environment, providing a sandbox for safe execution.
-
Flexibility:
- The system supports both production (
SANDBOX_UPDATE_SOURCE_CODE=False) and development (SANDBOX_UPDATE_SOURCE_CODE=True) modes. - In development mode, the runtime image can be updated with the latest code changes for testing and debugging.
- The system supports both production (