The 17-year-old, who remains unnamed for legal reasons, is also charged with assaulting the lads at Blundell’s School in Tiverton, Devon, and then hitting a teacher in the head multiple times with a hammer.
The 16-year-old alleges that he was sleepwalking at the time of the attacks.
Exeter Crown Court heard that the schoolboy, who was only sporting boxer shorts, had four claw hammers on him and had waited for the boys to be asleep before allegedly attacking them.
The two boys were in cabin-style beds in one of the mixed school’s boarding homes when the defendant climbed up and struck them with at least one hammer just before one in the morning on June 9, 2017, according to prosecutor James Dawes KC.
“The defendant was awake, and he decided to put into action a plan that he had been fermenting in his head for some time,” said Mr Dawes.