def METHOD_NAME(
    transformed_nb: TransformedNotebookContainer,
    output_dir: pathlib.Path,
    assignment: Assignment,
    sanitize: bool,
):
    """
    Write an output directory (either for the autograder or student, as indicated by ``sanitize``).
    Args:
        transformed_nb (``otter.assign.notebook_transformed.TransformedNotebookContainer``): the
            transformed notebook
        output_dir (``pathlib.Path``): the path to the output directory being written (assumed to
            already exist)
        assignment (``otter.assign.assignment.Assignment``): the assignment config
        sanitize (``bool``): whether to sanitize the output (by removing solutions and hidden tests)
    """
    output_path = output_dir / assignment.notebook_basename
    tests_dir = output_dir / "tests"
    if assignment.tests.files:
        os.makedirs(tests_dir, exist_ok=True)
    if not sanitize:
        if assignment.requirements:
            output_fn = ("requirements.txt", "requirements.R")[assignment.is_r]
            if isinstance(assignment.requirements, list):
                with open(str(output_dir / output_fn), "w+") as f:
                    f.write("\n".join(assignment.requirements))
                assignment.requirements = str(output_dir / output_fn)
            else:
                shutil.copy(assignment.requirements, str(output_dir / output_fn))
        if assignment.environment:
            output_fn = "environment.yml"
            shutil.copy(assignment.environment, str(output_dir / output_fn))
    # write tests
    transformed_nb.write_tests(str(tests_dir), not sanitize, assignment.tests.files)
    # write a temp dir for otter generate tests
    if not sanitize:
        assignment._temp_test_dir = pathlib.Path(tempfile.mkdtemp())
        transformed_nb.write_tests(str(assignment._temp_test_dir), True, True)
    transformed_nb.write_transformed_nb(output_path, sanitize)
    # copy files
    for file in assignment.files:
        # if a directory, copy the entire dir
        if os.path.isdir(file):
            shutil.copytree(file, str(output_dir / os.path.basename(file)))
        else:
            # check that file is in subdir
            if str(assignment.master.parent) not in os.path.abspath(file):
                raise ValueError(
                    f"{file} is not in a subdirectory of the master notebook directory")
            file_path = pathlib.Path(file).resolve()
            rel_path = file_path.parent.relative_to(assignment.master.parent)
            os.makedirs(output_dir / rel_path, exist_ok=True)
            shutil.copy(file, str(output_dir / rel_path))