A teenager who stabbed two students and a teacher at a high school in Sydney's west and threatened a third student with a knife will spend at least four years behind bars for the unprovoked attack.

The 18-year-old, who cannot be named because he was underage at the time, arrived at Bonnyrigg High School on February 2, 2017 with a backpack full of weapons and walked into morning roll call.

Police arrest the teenager, who cannot be named, over attacking two students and a teacher at Bonnyrigg. Credit:ninevms

Science teacher Carolyn Cox was in the classroom with about 10 other students and was opening a window when the teenager approached her from behind and stabbed her in the back with a kitchen knife as other students continued to enter the room.

She sustained a fractured rib and a penetrating injury to the lung. She collapsed and felt a wetness on her back.