All of the examples we've seen so far exist as scripts, separate from the actual scene that they are run in. That's fine for tools, but means that if you create a script that is tightly tied to a particular scene (such as a custom control UI for a character rig), you have to be careful to make sure that the script file is always distributed along with the Maya file.
For such situations, Maya offers a better way. Script nodes can be used to bake scripts directly into a scene, allowing them to be run without any external dependencies. Furthermore, script nodes can be created with code.
In this example, we'll create a script that will prompt the user for a Python file, and will then create a script node with the contents of the file, and set it up so that the script will be executed each time the file is opened.