Environments
An Environment is where generated code lives and gets tested. It provides file I/O, command execution, test running, and checkpointing — everything an agent needs to work with code. Chimera ships five environment implementations (LocalEnvironment, GitEnvironment, DockerEnvironment, RemoteEnvironment, CloudEnvironment), plus a SessionMixin for persistent shell sessions.
The Environment ABC
Section titled “The Environment ABC”The base class in chimera.env.base defines the interface every environment must implement:
class Environment(ABC): def setup(self) -> None: ... def cleanup(self) -> None: ... def read_file(self, path: str) -> str: ... def write_file(self, path: str, content: str) -> None: ... def list_files(self, pattern: str = "**/*") -> list[str]: ... def run_command(self, cmd: str, timeout: int = 120, shell_name: str = "main") -> CommandResult: ... def run_tests(self) -> TestResult: ... def checkpoint(self) -> str: ... def restore(self, checkpoint_id: str) -> None: ...The interface covers file I/O (read_file, write_file, list_files), command execution (run_command, run_tests), and state management (checkpoint, restore). All environments support the context manager protocol:
from chimera.env.local import LocalEnvironment
with LocalEnvironment(workdir="./output", test_cmd="pytest") as env: env.write_file("hello.py", "print('hello')") result = env.run_command("python hello.py") print(result.stdout) # "hello\n"# cleanup() is called automatically on exitLocalEnvironment
Section titled “LocalEnvironment”The most commonly used environment. Operates directly on the local filesystem with file-copy-based checkpointing.
from chimera.env.local import LocalEnvironment
env = LocalEnvironment( workdir="./project", test_cmd="python -m pytest", timeout=300, session=False,)| Parameter | Default | Description |
|---|---|---|
workdir | (required) | Path to the working directory |
test_cmd | "python -m pytest" | Command to run the test suite |
timeout | 300 | Default timeout for commands (seconds) |
session | False | Enable persistent tmux shell session |
Checkpointing
Section titled “Checkpointing”LocalEnvironment uses file-copy checkpointing. Each call to checkpoint() copies the entire workspace (excluding the .chimera_checkpoints directory) to a numbered subdirectory. restore() reverses the process.
with LocalEnvironment(workdir="./project") as env: env.write_file("v1.py", "version = 1") cp1 = env.checkpoint() # Save state
env.write_file("v1.py", "version = 2") env.restore(cp1) # Roll back
content = env.read_file("v1.py") # "version = 1"Test Parsing
Section titled “Test Parsing”run_tests() executes the configured test_cmd and parses pytest-style output into a TestResult with passed, failed, errors, output, pass_rate, and all_passed properties.
GitEnvironment
Section titled “GitEnvironment”Extends LocalEnvironment with git-based checkpointing instead of file copies. Checkpoints become git commits, and restore uses git checkout.
from chimera.env.git_env import GitEnvironment
env = GitEnvironment( workdir="./project", test_cmd="python -m pytest",)On setup(), it initializes a git repo if one does not exist. Checkpoints are created via git add . && git commit, and restore uses git checkout <sha> -- ..