If you took a music box apart, you'd find that there's a tiny cylinder inside that is covered with tiny little bumps, or pins. The cylinder is rotated by a spring-driven motor, causing it to rotate. As it turns, the pins on the cylinder catch the teeth of a comb in a specific sequence, which creates the music.
The mechanics of how a music box works is very interesting. It has several working parts that interact around a cylinder and music is encrypted. You can find more information here: http://www.musicboxattic.com/leabmubo.html