A tragedy was only averted when a member of the public shouted a warning to the boy.
It is thought the boy had intended to leave the empty pram on the tracks, placing the Musselburgh-bound train at risk of derailment and putting passengers' lives at risk.
Constable Dona Davanna, from British Transport Police, is visiting nearby Campie Primary this week to warn pupils of the dangers of trespassing on the railways.
She said: "The dangers of messing about near the railway line cannot be exaggerated. Not only did this foolish young boy commit a crime, he also put his life and others at risk."
A British Transport Police spokesman said that crimes like the incident on Sunday morning were rare in the Lothians, and said the force did not regard the area as one of its "hot spots" for railway trespassing or obstructions on the line.
He said: "The majority of these incidents occur in the west of Scotland, particularly in Glasgow, Renfrewshire and Inverclyde, and pose a regular challenge for our officers."
An East Lothian Council spokeswoman said the education department was aware of Sunday's incident, which is being dealt with in line with its health and safety and child protection procedures. She added: "All East Lothian schools place great emphasis on educating children about personal safety when they are out and about.
"Our primaries will be re-iterating this message at assemblies this week."
It is not the first time trains approaching Musselburgh Station have been endangered by trespassing and obstructions.
A shopping trolley was believed to have damaged a train approaching the station in December last year, resulting in an oil leakage and delays to dozens of passengers.
In June last year, vandals as young as ten were thought to have left a wheelie bin on the Edinburgh to Bathgate line, which severed the brakes on a train.
BRIDGE CHAOS CAUSES DELAYS
MOTORISTS faced major disruption yesterday after pieces of metal were left hanging from a railway bridge in Newhaven.
Drivers were directed away from the East Mains Street area after concerns were raised about scaffolding left hanging above the road around 7am.
It is thought bad weather may have caused the metal poles to come loose.
The incident caused delays and queues until around 4pm.