There is one train a day between Belgrade and Sarajevo. The journey takes around 9 hours when it runs on time. The service isn't known for its reliability, so don't be surprised to arrive a few hours behind schedule. The train consists of three carriages, one of which is a restaurant car. Generally speaking, most of the people that use the service are tourists/backpackers, and very few locals use the service. The restaurant car doesn't tend to be that well stocked, so make sure that you bring extra food and drink for the journey. Be aware that there is no air conditioning on-board the train, which can get extremely hot and uncomfortable. Dress lightly and bring a fan and plenty of water to drink. The whole train is second class seating only, there is no first class option. Generally, the carriages are fairly dirty, but still more enjoyable than the alternative bus ride. You can read more about one journalist's expierences on this train here.
This route is currently suspended.