Skip to content

SWE-rex Docker

SWE-rex Docker Environment class

minisweagent.environments.extra.swerex_docker

SwerexDockerEnvironmentConfig

Bases: BaseModel

image instance-attribute

image: str

cwd class-attribute instance-attribute

cwd: str = '/'

Working directory in which to execute commands.

timeout class-attribute instance-attribute

timeout: int = 30

Timeout for executing commands in the container.

deployment_extra_kwargs class-attribute instance-attribute

deployment_extra_kwargs: dict[str, Any] = {}

Extra kwargs to pass to DockerDeployment.

SwerexDockerEnvironment

SwerexDockerEnvironment(**kwargs)

This class executes bash commands in a Docker container using SWE-ReX for sandboxing.

Source code in src/minisweagent/environments/extra/swerex_docker.py
23
24
25
26
27
def __init__(self, **kwargs):
    """This class executes bash commands in a Docker container using SWE-ReX for sandboxing."""
    self.config = SwerexDockerEnvironmentConfig(**kwargs)
    self.deployment = DockerDeployment(image=self.config.image, **self.config.deployment_extra_kwargs)
    asyncio.run(self.deployment.start())

config instance-attribute

config = SwerexDockerEnvironmentConfig(**kwargs)

deployment instance-attribute

deployment = DockerDeployment(
    image=image, **(deployment_extra_kwargs)
)

execute

execute(
    action: dict,
    cwd: str = "",
    *,
    timeout: int | None = None,
) -> dict[str, Any]

Execute a command in the environment and return the raw output.

Source code in src/minisweagent/environments/extra/swerex_docker.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def execute(self, action: dict, cwd: str = "", *, timeout: int | None = None) -> dict[str, Any]:
    """Execute a command in the environment and return the raw output."""
    command = action.get("command", "")
    try:
        result = asyncio.run(
            self.deployment.runtime.execute(
                RexCommand(
                    command=command,
                    shell=True,
                    check=False,
                    cwd=cwd or self.config.cwd,
                    timeout=timeout or self.config.timeout,
                    merge_output_streams=True,
                )
            )
        )
        output = {"output": result.stdout, "returncode": result.exit_code, "exception_info": ""}
    except Exception as e:
        output = {
            "output": str(e) if str(e) else "",
            "returncode": -1,
            "exception_info": f"An error occurred while executing the command: {e}",
            "extra": {"exception_type": type(e).__name__, "exception": str(e)},
        }
    self._check_finished(output)
    return output

get_template_vars

get_template_vars(**kwargs) -> dict[str, Any]
Source code in src/minisweagent/environments/extra/swerex_docker.py
69
70
def get_template_vars(self, **kwargs) -> dict[str, Any]:
    return recursive_merge(self.config.model_dump(), kwargs)

serialize

serialize() -> dict
Source code in src/minisweagent/environments/extra/swerex_docker.py
72
73
74
75
76
77
78
79
80
def serialize(self) -> dict:
    return {
        "info": {
            "config": {
                "environment": self.config.model_dump(mode="json"),
                "environment_type": f"{self.__class__.__module__}.{self.__class__.__name__}",
            }
        }
    }