mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-28 00:18:25 -05:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user