The train driver's wife said three secondary school boys were ''playing chicken'' with her husband's train about 8.35am on Wednesday.
''Three kids who clearly don't value their lives. They need to realise the train can't just stop.''
The driver was forced to apply its emergency brakes.
In a separate incident, the driver also had to apply emergency brakes when a teenager with headphones on, oblivious to the train behind him, was walking in the middle of the tracks.
It scared ''the hell out of the driver'', his wife said.
KiwiRail zero harm manager Aaron Templeton said the incident with the three schoolboys in uniform occurred on the main trunk line near Waitaki Boys' High School.
''These boys are very lucky.''
Their behaviour was incredibly foolish, he said.
''People need to think about the potential ramifications from foolish actions such as these.
''This kind of behaviour could have, and has in the past, resulted in people being killed.''
KiwiRail struggled to understand why people continued to ignore the dangers of walking on railway tracks, given the recent sequence of fatal accidents involving trespassers on rail lines.
''The public must understand that it is illegal to be walking in the rail corridor in the first instance and that it is extremely dangerous to do so.
''A train is travelling at around 80kmh and will take at least half a kilometre to come to a halt.''
KiwiRail had spoken to Waitaki Boys' High School rector Paul Jackson and the school would address the issue with pupils at today's assembly, attempting to identify the boys involved.