The most common source of this error seems to be use of ‘global’ variables inside a graded function. The code runs fine in the Jupyter notebook because of the namespace and scope, but fails when executed as a standalone function in the autograder environment. See for example this similar thread:
However, this one is also very interesting and doesn’t seem to be programmer self-inflicted: