Repository navigation
Commit dd9c759
committed
Make ContainerEnvironment pluggable so non-Docker backends can run eval
The eval pipeline assumes Docker is the only container runtime: `Evaluator._new_env`
constructs `ContainerEnvironment(...)` directly, and `_copy_file_from_container`
shells `docker cp` by reaching into `env.executable` / `env.container_id`.
That blocks anyone running ProgramBench inside an environment that doesn't
support Docker-in-Docker (cloud sandboxes, gVisor, firecracker, most CI
runners that share a single Docker daemon). They have to monkey-patch
internals to swap the backend.
This change introduces two Protocols (`Environment`, `ContainerBackend`)
and threads an optional `backend` kwarg through `Evaluator.__init__`. The
default is `DockerBackend()` — same behavior as today; the byte-identical
test suite confirms it.
Concrete changes:
- `Environment` Protocol codifies the surface `Evaluator` already uses:
`execute`, `copy_in`, `copy_in_tar`, `copy_out` (new), `commit`,
`cleanup`. Plus `cwd` and `default_timeout` attributes that
`_run_test_branch` reads directly.
- `ContainerEnvironment.copy_out(container_path, *, timeout)` is new.
It replaces the direct `docker cp` call that lived in
`_copy_file_from_container`. Returns `(contents, command_string)` so
the caller can log the wire command without knowing the backend's
format.
- `ContainerBackend` Protocol with `new_env(image, *, cwd, timeout, cpus,
env, run_args)` and `remove_image(image_ref)`.
- `DockerBackend` is the default implementation: wraps
`ContainerEnvironment` and the module-level `remove_image` helper.
Preserves the `executable` and base `run_args` plumbing.
- `Evaluator.__init__` accepts `backend: ContainerBackend | None = None`,
defaulting to `DockerBackend(executable=DOCKER_EXECUTABLE, run_args=DOCKER_RUN_ARGS)`.
- `Evaluator._new_env` delegates to `self.backend.new_env(...)`. The
baseline xdist hardening (PYTEST_ADDOPTS, serial_pytest, --init in
run_args) is unchanged.
- `Evaluator._copy_file_from_container` collapses from ~45 lines of
subprocess plumbing to a single `env.copy_out(...)` call plus the
same step-log entry shape it always wrote. Removed `tempfile` and
`subprocess` imports from eval.py (now only needed in container.py).
- `Evaluator.run`'s final `remove_image(committed_image, ...)` call
becomes `self.backend.remove_image(committed_image)`.
Tests:
- `tests/test_pluggable_backend.py` adds 3 examples:
* Building an Evaluator with a FakeBackend routes `_new_env` and
`_copy_file_from_container` through the fake (no Docker shellouts).
* No `backend=` kwarg → DockerBackend.
* DockerBackend satisfies the ContainerBackend Protocol structurally.
- All 28 existing tests still pass; 31/31 with the new ones.
Motivating use case: saul-agent-infra runs the eval inside Daytona
sandboxes which can't run Docker. Today we monkey-patch
`programbench.container.ContainerEnvironment`, `Evaluator._copy_file_from_container`,
and `Evaluator._restore_executable`. After this PR the first two go
away entirely. (The third, swapping `mv` for `cp` to handle serial
test branches without re-imaging, is a small separate fix worth its
own discussion.)1 parent b33e660 commit dd9c759
3 files changed
Lines changed: 253 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | | - | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 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 | + | |
| 55 | + | |
18 | 56 | | |
19 | 57 | | |
20 | 58 | | |
| |||
116 | 154 | | |
117 | 155 | | |
118 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
119 | 183 | | |
120 | 184 | | |
121 | 185 | | |
| |||
206 | 270 | | |
207 | 271 | | |
208 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
40 | 38 | | |
41 | 39 | | |
42 | 40 | | |
43 | | - | |
| 41 | + | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
| |||
295 | 293 | | |
296 | 294 | | |
297 | 295 | | |
| 296 | + | |
298 | 297 | | |
299 | 298 | | |
300 | 299 | | |
| |||
310 | 309 | | |
311 | 310 | | |
312 | 311 | | |
| 312 | + | |
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| |||
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
397 | | - | |
| 397 | + | |
398 | 398 | | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
403 | 404 | | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | 405 | | |
409 | 406 | | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
| 407 | + | |
| 408 | + | |
416 | 409 | | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
443 | 429 | | |
444 | 430 | | |
445 | 431 | | |
| |||
456 | 442 | | |
457 | 443 | | |
458 | 444 | | |
459 | | - | |
460 | | - | |
| 445 | + | |
| 446 | + | |
461 | 447 | | |
462 | | - | |
463 | 448 | | |
464 | 449 | | |
465 | 450 | | |
466 | | - | |
| 451 | + | |
467 | 452 | | |
468 | 453 | | |
469 | 454 | | |
| |||
839 | 824 | | |
840 | 825 | | |
841 | 826 | | |
842 | | - | |
| 827 | + | |
843 | 828 | | |
844 | 829 | | |
845 | 830 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 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 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
0 commit comments