From 6faabef24d9621513d1ccde998d875412ccffd46 Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Tue, 20 Jan 2026 23:57:02 -0600 Subject: [PATCH] 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 --- .../forge/forge/components/code_executor/code_executor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/classic/forge/forge/components/code_executor/code_executor.py b/classic/forge/forge/components/code_executor/code_executor.py index 9746f5e428..a136405362 100644 --- a/classic/forge/forge/components/code_executor/code_executor.py +++ b/classic/forge/forge/components/code_executor/code_executor.py @@ -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)