def cleanup_code(code: str) -> str:
    """
    Automatically removes code blocks from the code.
    Parameters
    ----------
    code
        The code to clean.
    Returns
    -------
    str
        The cleaned code.
    """
    # remove ```py\n```
    if code.startswith('```') and code.endswith('```'):
        return '\n'.join(code.split('\n')[1:-1])

    # remove `foo`
    return code.strip('` \n')