There is a direct train 051 from Lviv to Krakow; yet it is quite slow (9+ hours for the entire journey), expensive (it seems that tickets start from 60EUR); while the reservation is compulsory, there is no way to purchase tickets online (or is there?); and they say that on the border custom officers literally tear the train apart to fight the smugglers (which should be quite an unpleasant experience).
On the other hand, Lviv is just 90km from the border, and there are fast (4-5 hours) and cheap (9EUR) PKP Intercity trains from Przemysl to Krakow, with tickets available for online booking on PKP website.
It seems that the easiest way to get to Krakow would be to somehow get to the border, pass it by feet, and get to the Intercity train. However, it is unclear:
1) How to get from Lviv to the border? There are some commuter trains from Lviv to Mostiska (2hrs), and some buses from Lviv to Scheginy (1:30hrs), but how reliable are these?
2) Is it hard to get from said train/bus to the checkpoint itself, and from the checkpoint to the Przemysl station?
3) How long does it usually take to cross the border? Or, put in other words, how long in advance should you arrive to the checkpoint (or Mostiska or Scheginy stations) to safely reach Przemysl station in time for the Intercity train?