def get_wrapped_env_by_class(env, env_class):
    """Traverses the wrapped environments until it
    finds the one from the given class.

    :return: The environment that is an instance of the given `env_class`.
    """
    while not isinstance(env, env_class):
        env = env.unwrapped
    return env