If you are running on a fixed track, by far the easiest method is to use a pair of endstops.
Typically these would be mechanical, magnetic or optical.
A mechanical endstop could be as simple as a physical barrier at the end of your track, much like a train track buffer stop. Your vehicle would bump up to buffer, detect that it wasn't moving and take that as a signal that it had reached the end of travel.
If you are moving slowly, with low toque and the restraining force of the buffer is significantly greater than the motive force of the vehicle plus the force from dissipating the momentum of the vehicle, then a simple mechanical endstop might be sufficient.
If you want to get a little more sophisticated, you could add a mechanical switch to your vehicle bumpers, ideally on a spring such that it is closed before the main body of the vehicle hits the buffer. When the buffer stop is close, the control system would be told by the closing of the switch that and could apply the brakes.
A magnetic endstop would be a magnet on the track with a reed-switch attached to your control system. When the reed switch rolls over the magnet, the circuit is closed and the control system can stop the vehicle.
This has the advantage over the mechanical switch that it is non contact, so is less likely to be damages if the vehicle becomes a run-away.
An optical endstop would be a slotted optical switch on the vehicle and a blade of metal near the end of travel on the track, which runs through optical switch, blocking the beam when the vehicle gets close to the end of travel.
This has the advantage that rather than relying on a magnet that is in one spot on the track being detected, it can signal an end of travel condition for the whole distance from the end of required travel right up to any mechanical endstop.
Essentially, this is just keeping track of where you have commanded your stepper motor to move and applying limits on how far you allow the higher level software to move. If you are requesting motion which is well within the parameters of the motor you have specified for your vehicle (speed, torque and acceleration profile etc.), then it should not be skipping steps and soft end-stops may well be sufficient.
If you do this though, I would also recommend adding one of the other mechanisms as belt and braces.
Most industrial systems have multiple end of travel detection and over travel prevention systems, usually soft limits and either a mechanical endstop plus limit switches or soft limits, mechanical endstop plus opto endstop. All three systems have to fail in order for the system fail overall.
You might also want to have a look at the answers to Why do I need an endstop sensor with stepper motor? over on Electrical Engineering Stack exchange.