fix(classic): always recreate Docker containers for code execution

Docker containers cannot have their mount bindings updated after creation.
When running benchmarks or multiple agent instances, the same container name
could be reused with a different workspace directory, causing the container
to still reference the OLD mount path. This resulted in "python: can't open
file '/workspace/temp*.py'" errors.

The fix: remove existing containers before creating new ones to ensure fresh
mount bindings to the current workspace directory.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Nicholas Tindle
2026-01-20 23:57:02 -06:00
parent a67d475a69
commit 6faabef24d

View File

@@ -453,6 +453,14 @@ class CodeExecutorComponent(
container: DockerContainer = client.containers.get(
container_name
) # type: ignore
# Remove existing container - it may have stale mounts from
# a previous run with a different workspace directory
logger.debug(
f"Removing existing container '{container_name}' "
"to refresh mount bindings"
)
container.remove(force=True)
raise NotFound("Container removed, recreating")
except NotFound:
try:
client.images.get(image_name)