def run_skeleton_task():
    '''Generic skeleton for running any task in your simulation.'''
    print("===== Starting Skeleton Task =====")
    
    # === Environment Setup ===
    env, task = setup_environment()
    try:
        # Reset the task to its initial state
        descriptions, obs = task.reset()

        # (Optional) Initialize video writers for capturing your simulation
        init_video_writers(obs)

        # Wrap the task steps for recording (if needed)
        original_step = task.step
        task.step = recording_step(original_step)
        original_get_obs = task.get_observation
        task.get_observation = recording_get_observation(original_get_obs)

        # === Retrieve Object Positions ===
        positions = get_object_positions()

        # Assuming we have objects like 'drawer1', 'drawer2', etc. in the environment
        drawer1_pos = positions['drawer1']
        drawer2_pos = positions['drawer2']
        gripper_pos = positions['gripper']

        # Example Task Plan
        # 1) Move to drawer1
        print("[Task] Moving to drawer1 at:", drawer1_pos)
        obs, reward, done = move(env, task, gripper_pos, drawer1_pos)
        if done:
            print("[Task] Task ended after moving to drawer1!")
            return

        # 2) Pick the drawer
        print("[Task] Picking drawer1")
        obs, reward, done = pick(env, 'drawer1', drawer1_pos, 'gripper')
        if done:
            print("[Task] Task ended after picking drawer1!")
            return

        # 3) Open the drawer
        print("[Task] Opening drawer1")
        obs, reward, done = pull(env, 'gripper', 'drawer1')
        if done:
            print("[Task] Task ended after opening drawer1!")
            return

        # 4) Move to drawer2
        print("[Task] Moving to drawer2 at:", drawer2_pos)
        obs, reward, done = move(env, task, drawer1_pos, drawer2_pos)
        if done:
            print("[Task] Task ended after moving to drawer2!")
            return

        # 5) Place the drawer
        print("[Task] Placing drawer1 in drawer2")
        obs, reward, done = place(env, 'drawer1', drawer2_pos)
        if done:
            print("[Task] Task ended after placing drawer1 in drawer2!")
            return

    finally:
        # Always ensure the environment is properly shutdown
        shutdown_environment(env)

    print("===== End of Skeleton Task =====")


if __name__ == "__main__":
    run_skeleton_task()