Skip to content

SWE-rex Docker

minisweagent.environments.extra.swerex_docker

SwerexDockerEnvironmentConfig dataclass

SwerexDockerEnvironmentConfig(
    image: str,
    cwd: str = "/",
    timeout: int = 30,
    deployment_extra_kwargs: dict[str, Any] = dict(),
)

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] = field(
    default_factory=dict
)

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
21
22
23
24
25
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(command: str, cwd: str = '') -> dict[str, Any]

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

Source code in src/minisweagent/environments/extra/swerex_docker.py
27
28
29
30
31
32
33
34
35
36
37
38
39
def execute(self, command: str, cwd: str = "") -> dict[str, Any]:
    """Execute a command in the environment and return the raw output."""
    output = asyncio.run(
        self.deployment.runtime.execute(
            RexCommand(
                command=command, shell=True, check=False, cwd=cwd or self.config.cwd, timeout=self.config.timeout
            )
        )
    )
    return {
        "output": f"<stdout>\n{output.stdout}</stdout>\n<stderr>\n{output.stderr}</stderr>",
        "returncode": output.exit_code,
    }