Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions autogen/code_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def execute_code(
timeout: Optional[int] = None,
filename: Optional[str] = None,
work_dir: Optional[str] = None,
use_docker: Optional[Union[List[str], str, bool]] = True,
use_docker: Optional[Union[List[str], str, bool]] = None,
lang: Optional[str] = "python",
) -> Tuple[int, str, str]:
"""Execute code in a docker container.
Expand All @@ -242,7 +242,8 @@ def execute_code(
If a list or a str of image name(s) is provided, the code will be executed in a docker container
with the first image successfully pulled.
If None, False or empty, the code will be executed in the current environment.
Default is True, which will be converted into a list.
Default is None,
If True, which will be converted into a list.
If the code is executed in the current environment,
the code must be trusted.
lang (Optional, str): The language of the code. Default is "python".
Expand All @@ -260,11 +261,15 @@ def execute_code(
# Warn if docker was requested but cannot be provided. In this case
# the current behavior is to fall back to run natively, but this behavior
# is subject to change.
if use_docker and docker is None:
use_docker = False
logger.warning(
"execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change"
)
if use_docker is not None:
if not docker:
if use_docker is True:
raise Exception("Docker is not installed, but use_docker is set to True.")
else:
logger.warning(
"Docker is not installed. Falling back to native code execution. Note: this fallback behavior is subject to change"
)
use_docker = False

timeout = timeout or DEFAULT_TIMEOUT
original_filename = filename
Expand Down