If it's just a passport check they're after, that's fairly easy (though there's always potential for somebody to duck into a restroom or similar).
Customs declarations are usually made at the entry-point (at least with international air travel) - but I don't know how trains do that today (all my train travel was Schengen zone in the late 90s - just passport checks on the train, and only between some countries).