Chester police say they were contacted by security personnel from the high school around 7:50 a.m.
The teen was caught after security spotted the gun when the sophomore went through a metal detector, which everyone coming into the school has to pass through.
"The gun that was confiscated was a 9mm firearm," said Chester Police Commissioner Stephen Gretsky. " It had an extended clip and it's also untraceable, which is known as a ghost gun."
Security was able to secure the firearm and the teen was taken to the Chester Detention Center.
There is no word on a motive for bringing the gun to school.
"I commend the Chester-Upland School District on having security measures in place at the school entrance, and the school security officer for detaining the student without incident. These security measures and quick actions prevented what could have been a terrible tragedy in our schools with our community's youth," said Chester Mayor Stefan Roots in a statement.