There are many horror stories about rat, lizard found in food ordered in Indian Railways. Many of these stories are indeed true.
Not only there were incidents where food was contaminated and rats/cockroacheswere found in it. CAG (Central Govt Audit Report) has conducted an investigation and found that Railway Food is unfit for consumption.
I personally would not recommend getting food from pantry. I had however few times indeed consumed food in the past without major consequences. But after i came to know about such complaints and reports i avoid eating that food without any exception.
You can order through third party Apps/Websites which will deliver packed food in your train compartment. They are much better option as they maintain good standards and there have nt been any complaints regarding them so far (at least in the mainstream media).
It is best to either take packed food, or buy packaged snacks. This is what i do and recommend. Anything else is risk not worth taking. Who wants a “Delhi belly” while traveling?
In a nutshell avoid buying food from pantry cars. If you are hungry buy some biscuits or chips. Or order it online via mobile apps.
Here is a list of few third party services that provide food in your compartment
Which one of these services is best?
It is hard to tell, most of these companies are just service providers and they tie up with local restaurants to deliver the food. So it is as safe or risky as eating at an average restaurant in India.
But in general these companies will take extra care to tie up with only the good restaurants because their business will depend on word of mouth and repeat business.