microsoft/autogen · error · ValueError
No code blocks to execute.
Error message
No code blocks to execute.
What it means
Raised by DockerCommandLineCodeExecutor._execute_code_dont_check_setup (and the public execute_code_blocks path) when the code_blocks list passed in is empty. It is a simple fail-fast validation: there is nothing to execute, and the API refuses rather than returning an empty result.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py:334
logging.debug(f"Kill command scheduled, future: {future!r}")
except RuntimeError as e:
logging.error(f"Failed to schedule kill command on loop {self._loop!r}: {e}")
except Exception as e:
logging.exception(f"Unexpected error scheduling kill command: {e}")
else:
logging.warning(
f"Cannot schedule kill command: Executor loop is not available or closed (loop: {self._loop!r})."
)
return "Code execution was cancelled.", 1
async def _execute_code_dont_check_setup(
self, code_blocks: List[CodeBlock], cancellation_token: CancellationToken
) -> CommandLineCodeResult:
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.")
if len(code_blocks) == 0:
raise ValueError("No code blocks to execute.")
outputs: List[str] = []
files: List[Path] = []
last_exit_code = 0
try:
for code_block in code_blocks:
lang = code_block.language.lower()
code = silence_pip(code_block.code, lang)
# Check if there is a filename comment
try:
filename = get_file_name_from_content(code, self.work_dir)
except ValueError:
outputs.append("Filename is not in the workspace")
last_exit_code = 1
break
if not filename:View on GitHub (pinned to 027ecf0a37)
Solutions
- Guard the call: only invoke the executor when code_blocks is non-empty
- Fix the extraction logic so an empty result is handled before reaching the executor (log the raw message to see why extraction failed)
- Return a neutral CodeResult yourself if your agent protocol expects one for empty turns
Example fix
# before
result = await executor.execute_code_blocks(extract_blocks(msg), ct) # may be []
# after
blocks = extract_blocks(msg)
if not blocks:
return CodeResult(exit_code=0, output="No code blocks to execute.")
result = await executor.execute_code_blocks(blocks, ct) Defensive patterns
Strategy: validation
Validate before calling
from autogen_core.code_executor import CodeResult
async def execute_safe(executor, blocks, ct) -> CodeResult:
if not blocks:
return CodeResult(exit_code=0, output="No code blocks to execute.")
return await executor.execute_code_blocks(blocks, ct) Type guard
def has_code_blocks(blocks) -> bool:
return isinstance(blocks, list) and len(blocks) > 0 Try / catch
null
Prevention
- Filter then check: never forward extraction results without a non-empty assertion
- Log the source message when extraction yields zero blocks — it usually means the model produced no code fence
When it happens
Trigger: Calling execute_code_blocks([], cancellation_token); passing a filtered list where every block was dropped (e.g. selecting only 'python' blocks from an LLM message that contained none); splitting an empty string into blocks programmatically.
Common situations: Agents whose last message contained no code fences; upstream code that extracts code blocks via regex and forwards an empty list when extraction fails; loops over messages where some messages legitimately have no code.
Related errors
- Functions failed to load: {exec_result.output.strip()}
- Timeout must be greater than or equal to 1.
- Module name must be a valid Python identifier
- Functions failed to load: {exec_result.output}
- Custom image {image_name} does not exist
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/5e5d64ab9d7c4c8f.
Report an issue: GitHub.