docs: def _create_environment(config, outdir):
    """Constructor for an instance of the environment.
  
    Args:
      config: Object providing configurations via attributes.
      outdir: Directory to store videos in.
  
    Raises:
      NotImplementedError: For action spaces other than Box and Discrete.
  
    Returns:
      Wrapped OpenAI Gym environment.
    """
    if isinstance(config.env, str):
      env = gym.make(config.env)
    else:
      env = config.env()
    # Ensure that the environment has the specification attribute set as expected
    # by the monitor wrapper.
    if not hasattr(env, 'spec'):
      setattr(env, 'spec', getattr(env, 'spec', None))
    if config.max_length:
      env = tools.wrappers.LimitDuration(env, config.max_length)
    env = gym.wrappers.Monitor(
        env, outdir, lambda unused_episode_number: True)
    if isinstance(env.action_space, gym.spaces.Box):
      env = tools.wrappers.RangeNormalize(env)
      env = tools.wrappers.ClipAction(env)
    elif isinstance(env.action_space, gym.spaces.Discrete):
      env = tools.wrappers.RangeNormalize(env, action=False)
    else:
      message = "Unsupported action space '{}'".format(type(env.action_space))
      raise NotImplementedError(message)
    env = tools.wrappers.ConvertTo32Bit(env)
    env = tools.wrappers.CacheSpaces(env)
    return env