Gameshark works by altering memory contents. The "codes" are memory addresses and the replacement contents (though there are some types that have special functions so that e.g. a range of values can be altered without entering many codes).
The "dongle" that comes with the Gameshark is for its own use in storing codes; it also doubles as a form of copy protection for the Gameshark. It has nothing to do with game saves. If you have a saved game that you want to improve, you can load up the GS, activate the codes to hardwire whatever stats/items/etc. you want, load your game and save it again. Since that saves the altered values to your VMU/memcard, you can now load it up again without the GS and have those same stats/items/whatever.