The train between Naples and Sorrento is a very cheap and quick way to travel between the two cities. Unfortunately, it also happens to be one of the worst in terms of pick-pocketing. There are countless stories floating around of tourists being targetted, so be aware. If you are set on using this train service, wear a money belt or be very aware of the potential for pickpockets.
Trains travel to/from the main station at Naples (Stazione Napoli Centrale on Piazza Garibaldi) regularly throughout the day, and travel along the cost between the city and Sorrento. Some trains stop more often than others. If you are in a hurry to reach your destination, look out for 'Diretto' trains.
More information is available on the Circumvesuvian website, which also hosts a useful journey planner.