microsoft/autogen · error · ValueError

Failed to restart container. Logs: {logs_str}

Error message

Failed to restart container. Logs: {logs_str}

What it means

Raised by DockerCommandLineCodeExecutor.restart() when container.restart() returns but the container's status is no longer 'running' — i.e. the container came back up and immediately exited. The message embeds the container's logs to explain the crash. The executor also sets _running=False, so subsequent executions fail with the 'Container is not running' error until restarted properly.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py:430

        Returns:
            CommandlineCodeResult: The result of the code execution."""

        if not self._setup_functions_complete:
            await self._setup_functions(cancellation_token)

        return await self._execute_code_dont_check_setup(code_blocks, cancellation_token)

    async def restart(self) -> None:
        """(Experimental) Restart the Docker container code executor."""
        if self._container is None or not self._running:
            raise ValueError("Container is not running. Must first be started with either start or a context manager.")

        await asyncio.to_thread(self._container.restart)  # type: ignore
        if self._container.status != "running":
            self._running = False
            logs_str = self._container.logs().decode("utf-8")
            raise ValueError(f"Failed to restart container. Logs: {logs_str}")

    async def stop(self) -> None:
        """(Experimental) Stop the code executor.

        Stops the Docker container and cleans up any temporary files (if they were created), along with the temporary directory.
        The method first waits for all cancellation tasks to finish before stopping the container. Finally it marks the executor as not running.
        If the container is not running, the method does nothing.
        """
        if not self._running:
            return

        if self._temp_dir is not None:
            self._temp_dir.cleanup()
            self._temp_dir = None

        client = docker.from_env()
        try:
            try:

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Read the embedded logs_str — it contains the container's stdout/stderr explaining the exit
  2. If logs show OOM, raise Docker memory limits or reduce workload before restarting again
  3. Recreate the executor entirely (new instance + start()) since _running is now False: restart() alone will raise error 698
  4. Check `docker inspect <container> --format '{{.State.Status}} {{.State.ExitCode}}'` for the concrete state

Example fix

# before
await executor.restart()  # may raise with logs embedded

# after
try:
    await executor.restart()
except ValueError as e:
    print("container logs:", e)  # logs are in the message
    executor = DockerCommandLineCodeExecutor(image="python:3-slim")
    await executor.start()  # fresh container
Defensive patterns

Strategy: fallback

Validate before calling

null

Type guard

null

Try / catch

try:
    await executor.restart()
except ValueError as e:
    logs = str(e)  # contains "Failed to restart container. Logs: <container logs>"
    diagnose(logs)
    executor = DockerCommandLineCodeExecutor(image="python:3-slim")
    await executor.start()  # _running is now False; recreate instead

Prevention

When it happens

Trigger: Calling restart() on a container whose process crashes on startup: an entrypoint that exits, OOM-killed processes, or a daemon hiccup where the container enters 'exited'/'restarting' state after the restart call.

Common situations: Long-running agents that restart executors periodically hitting Docker daemon instability; containers with memory limits OOMing on restart; images whose main process had already been killed inside the container so restart revives a dead entrypoint.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/0bb0968f2b7cc8fd. Report an issue: GitHub.