A Gunn High student was arrested Thursday afternoon after he brought an Airsoft pellet gun to school, sparking campus-wide alarm that resulted in a 45-minute lockdown, Palo Alto police said.

Two students were spotted entering the campus parking lot in a convertible, with one holding the pellet gun on his lap, police said. After a dramatic search, police detained the young men, arresting 18-year-old Weston Healy. The Airsoft gun, which closely resembles an actual firearm and shoots small, plastic pellets, was found in the convertible’s trunk.

“I believe the suspect said he made a poor decision,” Palo Alto police Officer Marianna Villaescusa said.

Police were called at 2 p.m. by a Palo Alto city employee who saw a young man sitting in the passenger seat of the convertible with what looked like a rifle on his lap, Villaescusa said.

Classes had just let out for the day and students were packing up or walking down the school’s hallways when a “code red” lockdown was announced over the loudspeaker and teachers called them back inside.

“They just said, ‘This is a code red or something, this is not a drill,’ ” 15-year-old sophomore Taylor Aguon said.

“I was just kind of pulled into a classroom,” 16-year-old sophomore Ellyssa Wong added. “My friend like dragged me.”

The teachers barricaded the doors with classroom furniture, Villaescusa said. Anne Sommer, a 15-year-old freshman, said they didn’t have time to cover the windows in her science classroom, so students hid beneath lab tables.

“It was just kind of a surprise at first because we thought it was a drill,” Anne said. “Then we realized they were actually being really serious.”

As police were tracking down more information, a person called from nearby Los Robles Avenue to report hearing gunshots. Police also got a call from a student’s mother, who said her daughter was being held at gunpoint inside a classroom, Villaescusa said.

At that point, the department called Mountain View, Sunnyvale and Los Gatos police for backup. The Stanford University Department of Public Safety was already helping.

“We err on the side of safety,” Villaescusa said. “We treat everything 100 percent like it’s real.”

The registered owner of the vehicle was able to help police identify the students, Villaescusa said. Gunn Assistant Principal Phil Winston helped officers find them in a classroom, she said.

In addition to the Airsoft gun, police found two face masks, a shovel with a 4-inch pick, a hatchet with a removable saw, and a military-style knife with a 7-inch blade in the car.

“All in all, things worked out really well for all involved,” Villaescusa said. “Nobody was hurt and the system worked the way it is supposed to.”

Police also found the girl whose mother reported she was being held at gunpoint, and briefly detained the girl before she explained it was a miscommunication. She told her mother the school was on lockdown and her mother misunderstood. The girl was handcuffed “for less than one minute,” Villaescusa said.

“We didn’t know if she was involved or if she was part of what was going on,” Villaescusa said.

It was unclear Thursday afternoon what disciplinary action Healy could face from either the school or the city. Possessing an Airsoft gun in public is a municipal code violation in Palo Alto; Healy was arrested on suspicion of possessing a weapon on a school campus and booked into Santa Clara County jail. As of Thursday evening, Healy was still in custody, his bail set at $10,000, according to jail spokesman Mark Cursi.

District officials could not be reached for comment. Gunn Assistant Principal Kimberley Cowell sent an e-mail to parents around 3:20 p.m., explaining that “Gunn experienced a Code Red as a safety precaution.

“At no time were students or staff in danger,” the message read. “Students and staff did an excellent job of following the Code Red procedure and the Palo Alto Police Department’s response was immediate and extremely effective.”

Students said rumors were flying and there were “20 different stories” about what had happened and who was responsible. The experience was “pretty intense,” sophomore Taylor said.

“I kept thinking of the worst case,” she said.

E-mail Diana Samuels at dsamuels@dailynewsgroup.com.