Your code will only be run on the board if the board is connected to your computer
The board will only run the code in the code.py file.
You can save your code for the challenges in separate files and then copy the code you want to run into code.py.
If you unplug or reset the board before your computer finishes writing the file to your board, you can corrupt the drive. If this happens, you may lose the code you've written, so it's important to backup your code to your computer regularly.
Learn more about creating and editing code here.