KiwiRail says two young men who rode on the back of a moving train near Wellington put their lives at risk.
The men were caught on video by a driver, who posted it on the social networking site Instagram.
KiwiRail said the train would have been travelling at about 90-kilometres an hour.
Its metro general manager David Shepherd said not only did the men risk killing themselves, but also traumatising the people who would then have to deal with the consequences of their actions.
Police in the Hutt Valley are working on identifying the men.
KiwiRail said there were 418 incidents of trespassing on the rail corridor last year, up from 288 in 2013.