microsoft/autogen · error · ValueError

Timeout must be greater than or equal to 1.

Error message

Timeout must be greater than or equal to 1.

What it means

Constructor validation in LocalCommandLineCodeExecutor: timeout (seconds per command, default 60) must be >= 1. Zero/negative raises ValueError right after the safety UserWarning about executing code locally.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/local/__init__.py:172

                Callable[..., Any],
                FunctionWithRequirementsStr,
            ]
        ] = [],
        functions_module: str = "functions",
        cleanup_temp_files: bool = True,
        virtual_env_context: Optional[SimpleNamespace] = None,
    ):
        # Issue warning about using LocalCommandLineCodeExecutor
        warnings.warn(
            "Using LocalCommandLineCodeExecutor may execute code on the local machine which can be unsafe. "
            "For security, it is recommended to use DockerCommandLineCodeExecutor instead. "
            "To install Docker, visit: https://docs.docker.com/get-docker/",
            UserWarning,
            stacklevel=2,
        )

        if timeout < 1:
            raise ValueError("Timeout must be greater than or equal to 1.")
        self._timeout = timeout

        self._work_dir: Optional[Path] = None
        if work_dir is not None:
            # Check if user provided work_dir is the current directory and warn if so.
            if Path(work_dir).resolve() == Path.cwd().resolve():
                warnings.warn(
                    "Using the current directory as work_dir is deprecated.",
                    DeprecationWarning,
                    stacklevel=2,
                )
            if isinstance(work_dir, str):
                self._work_dir = Path(work_dir)
            else:
                self._work_dir = work_dir
            self._work_dir.mkdir(exist_ok=True)

        self._functions = functions

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Pass timeout >= 1 second (e.g. default 60).
  2. Clamp externally sourced values: timeout = max(1, int(raw)).
  3. If you actually want short waits, use a small positive value like 5, not 0.

Example fix

# before
executor = LocalCommandLineCodeExecutor(timeout=0)

# after
executor = LocalCommandLineCodeExecutor(timeout=60)
Defensive patterns

Strategy: validation

Validate before calling

timeout = int(os.getenv("LOCAL_EXEC_TIMEOUT", "60")) or 60
timeout = max(1, timeout)

Type guard

def is_valid_timeout(t: object) -> bool:
    return isinstance(t, int) and not isinstance(t, bool) and t >= 1

Try / catch

try:
    LocalCommandLineCodeExecutor(timeout=t)
except ValueError as e:
    if "Timeout" in str(e):
        executor = LocalCommandLineCodeExecutor(timeout=max(1, int(t)))
    else:
        raise

Prevention

When it happens

Trigger: LocalCommandLineCodeExecutor(timeout=0) or a negative timeout, usually from config/env parsing that yields 0 when unset or from millisecond-vs-second confusion.

Common situations: Defaults like int(os.getenv('LOCAL_TIMEOUT', 0)) when the var is unset, passing 60_000 (milliseconds) which silently works but means about 16 hours, computed timeouts underflowing to 0, tests with timeout=0 expecting immediate abort.

Understand the failure class

Related errors


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