Both. A logic bomb is a piece of code that can sometimes enter a system as a virus or may be placed there by a malicious hacker or operator.
All logic bombs tend to have one thing in common: they wait on a specific event before beginning to execute their instructions. This event could be a date/time, a certain keystroke, or the launch of a particular program.
An example of a logic bomb would be in the movie Jurassic Park when the park's computer programmer set the timer for his program that would shut down all of the power to sections of the island.