Then there are border crossings where they check passports. Such checks make it impossible to get uninterrupted sleep.
You don't have to accept such.
I recommend you ask them to tone down. If that does not work, talk to the conductor. Keep it friendly. As a last resort, you can try to interact in the conversation or play some music (like a DoS) but that might lead to one thing or another.
Recommend to not travel alone. That way, one person can stay on watch for your belongings. That, or don't have valuables with you (though you always do, such as your passport or ID). I remember using my ThinkPad as pillow in Central Europe. Which, btw, got electricity from the German train now driving through Balkan.
That being said, my experience is that other people also want to sleep at night. The majority does. Noise cancelling headset might help, but mind your belongings. If you end up with other people who are backpacking alone, they're in the same boat as you are. Effectively, you together defend your train coupee, in a kind of unwritten covenant. Either way, smart scam artists will be able to creep up when your defenses are down.
Check if you can book in advance. In Germany especially, this can save you 50-75% of the regular price, and you reserve a seat which means you can keep sleeping on that seat.
As or border crossings, in the old days I would give the conductor my passport in the evening and get it back in the morning. Not often nowadays, thanks to the Schengen agreement. But no border guard has ever woken me up. (Edit: For scale, I think I've entered ten different countries on night trains, no idea how many trips in total.)
The problem seems to be that their once glamorous image has been lost. At least in Europe, they have gained a somewhat dubious reputation over the last decades.
Deutsche Bahn stopped their night train services 2 years ago, they sold if off completely to the Austrian Federal Railways (ÖBB), which now run it with a profit. Their idea? Clean up the trains, fix the reputation and attract families. As a passenger, I am happy about that, they are also planning to extend the network. As a German, I am a bit sad that the Austrians are now running our night trains, but providing train services does not exactly seem to be the main area of expertise of Deutsche Bahn.
PS: in case anyone is wondering, this is what a standard 2 bed night train room looks like in Europe (only one bed is flipped out): https://fidelgastro83.files.wordpress.com/2010/01/img_1272.j...