It runs when you have a programmer connected to your computer via USB, but not when it is disconnected - correct?
It could be that with the programmer connected you are getting power to the microcontroller from the USB, but when you disconnect power from your battery / voltage regulator is not getting to the microcontroller.