Leftover spaghetti can be stored safely in the refrigerator for 3 to 4 days. If a person is in doubt, the rule of thumb is that they should throw any leftover food out.
A major factor in how long food, such as spaghetti, can be kept is how long the food has been kept at room temperature prior to saving it. A meal that has been cooked and immediately put back in the refrigerator for storage will have a longer shelf life. Leftover spaghetti brought home from a restaurant in a box or unsealed container at room temperature should ideally be eaten the next day. If food ever has spores or mold on it, or an odd smell, it should be thrown out immediately.