def complete_runtime(
    runtime: Runtime,
    instance: pd.Series,  # this argument is not required, but it is used to get the workspace_dir_name
) -> dict[str, Any]:
    """Complete the runtime for the agent.

    This function is called before the runtime is used to run the agent.
    If you need to do something in the sandbox to get the correctness metric after
    the agent has run, modify this function.
    """
    logger.info(f'{"-" * 50} BEGIN Runtime Completion Fn {"-" * 50}')
    obs: CmdOutputObservation

    agent_answer = None
    get_agent_result_cmd = instance.get_agent_result
    if get_agent_result_cmd is not None:
        script_name = 'get_agent_result.sh'

        with tempfile.TemporaryDirectory() as tmpdir:
            host_script_path = os.path.join(tmpdir, script_name)
            create_sh_file(host_script_path, get_agent_result_cmd)
            runtime.copy_to(
                host_script_path,
                '/workspace',
            )
            logger.info(f'Running get agent result cmd: {script_name}')

        action = CmdRunAction(
            command=f'chmod +x ./{script_name} && ./{script_name}',
        )
        logger.info(action, extra={'msg_type': 'ACTION'})
        obs = runtime.run_action(action)
        logger.info(obs, extra={'msg_type': 'OBSERVATION'})
        assert obs.exit_code == 0
        agent_answer = obs.content
    # IF the agent answer is not found, retrieve it from the history
    # We wait until the controller finishes

    final_ans = None
    if instance.ground_truth is not None:
        final_ans = instance.ground_truth
    else:
        get_ground_truth_cmd = instance.get_ground_truth
        if get_ground_truth_cmd is not None:
            script_name = 'get_ground_truth.sh'
            with tempfile.TemporaryDirectory() as tmpdir:
                host_script_path = os.path.join(tmpdir, script_name)
                create_sh_file(host_script_path, get_ground_truth_cmd)
                runtime.copy_to(
                    host_script_path,
                    '/workspace',
                )
            logger.info(f'Running get ground truth cmd: {script_name}')

            action = CmdRunAction(
                command=f'chmod +x ./{script_name} && ./{script_name}'
            )
            logger.info(action, extra={'msg_type': 'ACTION'})
            obs = runtime.run_action(action)
            logger.info(obs, extra={'msg_type': 'OBSERVATION'})
            final_ans = obs.content

    logger.info(f'{"-" * 50} END Runtime Completion Fn {"-" * 50}')
    return {
        'final_ans': final_ans,
        'agent_answer': agent_answer,
    }
Complete the runtime for the agent.

    This function is called before the runtime is used to run the agent.
    If you need to do something in the sandbox to get the correctness metric after
    the agent has run, modify this function.
    
evaluation/benchmarks/agent_bench/run_infer.py