Depending on the country, you will disembark the train to pass through customs (it’s not usually required to take your bags off the train with you). Passports will be stamped and you’ll reboard to continue your journey. In other countries, particularly in Europe where you’re travelling through a Schengen zone, border control agents will board the train to check passports and any visa requirements. On overnight trains, border crossings normally happen in the small hours of the morning. You will be woken to complete the customs formalities but should still have time to go back to sleep before you arrive at your destination.