Registry / devops / swe-rex

swe-rex

JSON →
library1.4.0pypypi✓ verified 24d ago

SWE-ReX (SWE-agent Remote Execution Framework) is a Python library designed for sandboxed code execution for AI agents. It provides a flexible runtime interface for interacting with shell environments, supporting execution locally or remotely across various platforms like Docker containers, AWS Fargate, Modal, and Daytona. This enables massively parallel agent runs and disentangles agent logic from infrastructure concerns, making it a core component for projects like SWE-agent. Currently at version 1.4.0, SWE-ReX maintains an active development cycle with regular updates enhancing backend support and overall stability.

pip install swe-rex
INSTALL
IMPORT
SIG · SWE-REX
S
swe-rex
devopspythonv1.4.0
Install
10.4s avg
Import
1126ms
Disk
70MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.934s · 83.4MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 10.4s · import 0.867s · 83MB
70MB installed
● package 70MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LocalDeployment
from swerex.deployment.local import LocalDeployment
DockerDeployment
from swerex.deployment.docker import DockerDeployment
CreateBashSessionRequest
from swerex.runtime.abstract import CreateBashSessionRequest
BashAction
from swerex.runtime.abstract import BashAction
Command
from swerex.runtime.abstract import Command

This quickstart demonstrates how to set up `swe-rex` with both local and Docker deployments. It shows how to execute single commands and interact with a persistent bash session. Remember that `LocalDeployment` executes commands directly on your machine without sandboxing. For sandboxed environments, `DockerDeployment` (or cloud deployments like Modal/Fargate/Daytona) are recommended.

import asyncio from swerex.deployment.local import LocalDeployment from swerex.deployment.docker import DockerDeployment from swerex.runtime.abstract import CreateBashSessionRequest, BashAction, Command import os async def run_code_with_deployment(deployment_type: str): if deployment_type == "local": # LocalDeployment runs on your machine WITHOUT sandboxing. Be cautious. deployment = LocalDeployment() print("Running locally (no sandboxing by default). Be careful with commands!") elif deployment_type == "docker": # DockerDeployment provides sandboxing # Ensure Docker is running. You might need to pull the image first if not cached. deployment = DockerDeployment(image="python:3.12") print("Running in a Docker sandbox...") else: raise ValueError("Invalid deployment type") try: await deployment.start() runtime = deployment.runtime # Execute one-off commands print(f"Executing: echo Hello, world! from {deployment_type}") result = await runtime.execute(Command(command=["echo", f"Hello, world! from {deployment_type}"])) print(f"Output: {result.stdout.strip()}\n") # Create a bash session for persistent state await runtime.create_session(CreateBashSessionRequest()) print(f"Running in session: export MYVAR='test_{deployment_type}'") await runtime.run_in_session(BashAction(command=f"export MYVAR='test_{deployment_type}'")) print(f"Running in session: echo $MYVAR") result_session = await runtime.run_in_session(BashAction(command="echo $MYVAR")) print(f"Output from session: {result_session.stdout.strip()}\n") finally: await deployment.stop() async def main(): print("--- Local Deployment Example ---") await run_code_with_deployment("local") print("\n--- Docker Deployment Example ---") await run_code_with_deployment("docker") if __name__ == "__main__": # os.environ['MODAL_TOKEN_ID'] = os.environ.get('MODAL_TOKEN_ID', '') # For ModalDeployment # os.environ['MODAL_TOKEN_SECRET'] = os.environ.get('MODAL_TOKEN_SECRET', '') # For ModalDeployment # ... similarly for AWS or Daytona credentials if used ... asyncio.run(main())
Debug
Known issues
gotchaWhen using `LocalDeployment`, commands are executed directly on your host machine without any sandboxing. Exercise extreme caution, especially with administrative commands.
fix
For sandboxed execution, use `DockerDeployment`, `ModalDeployment`, `FargateDeployment`, or `DaytonaDeployment`. Review commands thoroughly before execution in local mode.
affects: All versions
gotchaVersions prior to v1.2.1 could experience `TemporaryDirectory` cleanup issues on Windows, potentially leaving temporary files or directories behind.
fix
Upgrade to `swe-rex` version 1.2.1 or newer.
affects: <1.2.1
gotchaIn some Docker environments, particularly when integrating with tools like SWE-agent, the `swe-rex` server installed via `pipx` might not be correctly added to the system's `PATH` variable.
fix
Ensure that the `PATH` environment variable inside your Docker container explicitly includes the `pipx` installation directory (e.g., `ENV PATH="$PATH:/root/.local/bin/"`) after running `pipx ensurepath`.
affects: All versions, especially in custom Docker images
gotchaOlder versions (prior to v1.4.0) had a hardcoded Python runtime value which could lead to Docker build failures when running in default configurations or with specific projects like SWE-agent.
fix
Upgrade to `swe-rex` v1.4.0 or newer. This version includes a fix for the hardcoded Python runtime value, improving Docker build stability.
affects: <1.4.0
gotchaUsers might encounter 'Runtime did not start within timeout' errors, especially in CI/CD environments like GitHub Actions. This often indicates issues with port allocation or insufficient startup time.
fix
Check for available ports, increase `startup_timeout` in your deployment configuration (e.g., `DockerDeploymentConfig(startup_timeout=300.0)`), and ensure Docker/container runtime is properly configured and accessible within the environment.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'swe_rex'
The `swe-rex` package has not been installed in the Python environment where the code is being executed.
fix
pip install swe-rex
docker.errors.DockerException: Error while fetching server API version
The Docker daemon is either not running, or the current user lacks the necessary permissions to connect to the Docker socket, preventing `swe-rex` from interacting with Docker.
fix
Ensure Docker Desktop (or the Docker daemon) is running and verify that your user has permissions to access the Docker socket (e.g., by adding your user to the 'docker' group).
sh: 1: <command>: not found
The command you are trying to execute inside the `swe-rex` container is not installed or is not available in the container's system PATH.
fix
Either install the required package within the container's setup phase (e.g., using `setup_commands` in `init_container`) or use a custom Dockerfile with the `build_container` backend that includes the necessary tools.
modal.exception.ConnectionError: Could not connect to Modal.
The local Modal client cannot establish a connection with the Modal platform, often due to an inactive Modal CLI login, network issues, or problems with the Modal service itself.
fix
Ensure you are logged into Modal by running `modal login` in your terminal and check your network connection and Modal's service status.
AttributeError: module 'swe_rex' has no attribute 'DockerBackend'
Specific backend classes like `DockerBackend` are not directly available under the top-level `swe_rex` module and must be imported from their respective submodules.
fix
Import the backend class explicitly from its specific submodule, for example: `from swe_rex.backends.docker import DockerBackend`
Upgrade
Version history
1.4.0latest on PyPI · released Aug 14, 2025
Audit
Dependencies
pexpectrequiredCore dependency for interacting with child processes.
pydanticrequiredUsed for configuration and data validation.
python-multipartrequiredDependency for web server functionality.
richrequiredFor rich text and progress bar displays.
uvicornrequiredASGI server for running the remote runtime.
fastapirequiredWeb framework for the remote runtime server.
bashlexrequiredFor parsing bash commands.
requestsrequiredFor making HTTP requests.
modal-clientoptionalOptional, required for Modal deployments.
daytona-sdkoptionalOptional, required for Daytona deployments.
boto3optionalOptional, required for AWS Fargate deployments (implied by 'fargate' extra).
Agent activity
13 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources