The driver of a Glenrothes-bound train escaped unhurt after an object was thrown at his cab window.
British Transport Police are trying to track down two boys aged about 10.
The incident happened at around 8.40pm on Tuesday on the outskirts of Edinburgh. One of the boys was seen to throw an object at the train, smashing the cab window.
The train had left Newcraighall at 8.39pm. The pair were seen at Bruntstane station.
Both were described as having blond hair and wearing dark clothes. One was riding a bike.
No one was injured during the incident.
Sergeant Linda Shields of the BTP said: ”The consequences of these stupid boys’ actions could have been so much worse. I would appeal for anyone with knowledge of their identity to come forward as a matter of urgency.
”They were last seen making off in the direction of the Magdalene area of Brunstane and this is where they may reside.”
Earlier this year, the BTP made a plea for the public’s help in investigating a spate of crimes on Scotland’s rail network.
One of the most serious incidents happened on the line between Dunfermline and Rosyth in July, when a train struck a shopping trolley left on the track.
On the same day, a train struck a mountain bike believed to have been deliberately placed on the line near Livingston North station.
Other similar incidents during the summer involved items including a wheelie bin and metal bed frame.
The BTP’s Inspector Sue Maxwell said crimes increased during the school holidays.