code: def run_scenario_in_docker(
      work_dir, requirements, timeout=600, docker_image=None
  ):
      """
      Run a scenario in a Docker environment.
  
      Args:
          work_dir (path): the path to the working directory previously created to house this scenario instance
          timeout (Optional, int): the number of seconds to allow a Docker container to run before timing out
      """
  
      client = docker.from_env()
      image = None
  
      # If the docker_image is None, then we will fetch DEFAULT_DOCKER_IMAGE_TAG, if present,
      # or build it if missing.
      if docker_image is None:
          # Pull a suitable image
          try:
              image = client.images.get(DEFAULT_DOCKER_IMAGE_TAG)
          except docker.errors.ImageNotFound:
              print(
                  f"Building default Docker image '{DEFAULT_DOCKER_IMAGE_TAG}'. This may take a few minutes..."
              )
              try:
                  build_default_docker_image(
                      client, DEFAULT_DOCKER_IMAGE_TAG
                  )
                  image = client.images.get(DEFAULT_DOCKER_IMAGE_TAG)
              except docker.errors.DockerException:
                  print(
                      f"Failed to build image '{DEFAULT_DOCKER_IMAGE_TAG}'"
                  )
  
      # Otherwise get the requested image
      else:
          try:
              image = client.images.get(docker_image)
          except docker.errors.ImageNotFound:
              # pull the image
              print(f"Pulling image '{docker_image}'")
              try:
                  image = client.images.pull(docker_image)
              except docker.errors.DockerException:
                  print(f"Failed to pull image '{docker_image}'")
  
      # Prepare the run script
      with open(
          os.path.join(work_dir, "run.sh"), "wt", newline="\n"
      ) as f:
          f.write(
              f"""#
  export AUTOGEN_TESTBED_SETTING="Docker"
  umask 000
  
  # Read the environment variables
  . ./ENV
  
  # Run the global init script if it exists
  if [ -f global_init.sh ] ; then
      . ./global_init.sh
  fi
  
  # Run the scenario init script if it exists
  if [ -f scenario_init.sh ] ; then
      . ./scenario_init.sh
  fi
  
  # Run the scenario
  pip install -r {requirements}
  python scenario.py
  
  # Clean up
  rm ENV
  if [ -d .cache ] ; then
      rm -Rf .cache
  fi
  
  # Run the scenario finalize script if it exists
  if [ -f scenario_finalize.sh ] ; then
      . ./scenario_finalize.sh
  fi
  
  # Run the global finalize script if it exists
  if [ -f global_finalize.sh ] ; then
      . ./global_finalize.sh
  fi
  
  echo SCENARIO COMPLETE !#!#
  """
          )
  
      print(
          "\n\n"
          + work_dir
          + "\n==================================================================="
      )
  
      # Create and run the container
      abs_path = str(pathlib.Path(work_dir).absolute())
      container = client.containers.run(
          image,
          command=["sh", "run.sh"],
          working_dir="/workspace",
          detach=True,
          # get absolute path to the working directory
          volumes={abs_path: {"bind": "/workspace", "mode": "rw"}},
      )
  
      # Poll until the container is done, or we've timed out
      start_time = time.time()
      while (
          container.status != "exited"
          and time.time() - start_time < timeout
      ):
          # Reload the container object
          container.reload()
  
      if container.status != "exited":
          container.stop()
  
          logs = (
              container.logs().decode("utf-8").rstrip()
              + "\nDocker timed out.\n"
          )
          print(logs)
          with open(
              os.path.join(work_dir, "console_log.txt"), "wt"
          ) as f:
              f.write(logs)
  
          container.remove()
          return
  
      # get the container logs
      logs = container.logs().decode("utf-8").rstrip() + "\n"
      container.remove()
  
      print(logs)
      with open(os.path.join(work_dir, "console_log.txt"), "wt") as f:
          f.write(logs)
  
file_path: autogen/samples/tools/testbed/run_scenarios.py
imports: import os
  import errno
  import shutil
  import subprocess
  import json
  import sys
  import time
  import pathlib
  import argparse
  from autogen import config_list_from_json
label_desc: Use image node_id 4 for calling a global function with example usage: run_scenario_in_docker(work_dir, requirements, timeout, docker_image) without return types