@@ -61,7 +61,7 @@ def to_dict(self) -> dict[str, Any]:
6161class CodeGame (ABC ):
6262 name : str
6363
64- def __init__ (self , config : dict , * , tournament_id : str , local_output_dir : Path ):
64+ def __init__ (self , config : dict , * , tournament_id : str , local_output_dir : Path , keep_containers : bool = False ):
6565 """The CodeGame class is responsible for running games, i.e., taking a list of code
6666 from different agents/players and running them against each other.
6767 It also provides the environments for the game and agents to run in.
@@ -74,11 +74,13 @@ def __init__(self, config: dict, *, tournament_id: str, local_output_dir: Path):
7474 config: The overall config for the tournament.
7575 tournament_id: The id of the tournament.
7676 local_output_dir: The host/local directory to write logs to.
77+ keep_containers: Do not remove containers after games/agent finish.
7778 """
7879 self .url_gh : str = f"git@github.com:{ GH_ORG } /{ self .name } .git"
7980 self .artifacts : list [Path ] = []
8081 """Artifact objects that we might want to clean up after the game."""
8182 self .config : dict = config
83+ self ._keep_containers : bool = keep_containers
8284 self ._metadata : dict = {
8385 "name" : self .name ,
8486 "config" : self .config ["game" ],
@@ -156,6 +158,10 @@ def log_round(self, round_num: int) -> Path:
156158 def get_environment (self , branch_name : str | None = None ) -> DockerEnvironment :
157159 """Get docker container ID with the game code installed."""
158160 self .build_image ()
161+ if not self ._keep_containers :
162+ run_args = ["--rm" ]
163+ else :
164+ run_args = []
159165 environment = DockerEnvironment (
160166 image = self .image_name ,
161167 cwd = str (DIR_WORK ),
@@ -169,6 +175,7 @@ def get_environment(self, branch_name: str | None = None) -> DockerEnvironment:
169175 },
170176 container_timeout = "3h" ,
171177 logger = self .logger ,
178+ run_args = run_args ,
172179 )
173180 # Logger setting will likely not take effect for initial container creation logs
174181 environment .logger = get_logger ("environment" , emoji = "🪴" )
0 commit comments