SAN JOSE (CBS SF) — Santa Clara County Sheriff’s deputies are investigating how a handcuffed suspect was able to gain access to an officer’s gun, which had been secured in the back of a San Jose police patrol SUV early Wednesday morning.

“This is just an example of a very determined suspect that is willing to do anything to get out of custody and escape,” said Santa Clara County Deputy Michael Low.

READ MORE: 200-Acre Mendocino County Vegetation Fire 20% Contained

Joseph Castro, 40, was initially arrested on charges of mail theft and violating his probation.

According to Low, a San Jose police officer had driven down the ramp toward the inmate intake area of the Santa Clara County Main Jail on W. Hedding Street at 1:39 a.m. when Castro managed to break into the cargo area of the vehicle and access the officer’s gun.

Santa Clara County Jail standoff suspect Joseph Castro (Santa Clara County Sheriff’s Office)

“The officer did attempt to restrain him and stop that suspect when he realized that something was going on,” Low said.

A source told KPIX that Castro was kicking the windows as he being taken to jail, and that he was able to get his handcuffed hands to the front of his body. He then kicked the plexiglass between the back seat and the trunk where the gun had been secured by the officer moments before, the source said.

According to Low, the officer had placed all his weapons in the rear compartment as they are trained to do before moving suspects out of the car to complete the booking process.

“Once the suspect had control of the firearm, the officer ran to a safe location and called for assistance,” Low said.

READ MORE: Curry Hits 10 3s, Scores 49 in Warriors' Win in Philly

Sources told KPIX that Castro was able to fire at least a half dozen rounds toward the officer before he ran to safety, and that Castro was locked inside the SUV the entire time.

Deputies and officers from the sheriff’s office and police department, as well as the Santa Clara Police Department and the California Highway Patrol arrived to help take Castro into custody.

The Sheriff’s Emergency Response Team and Crisis Negotiation Team also responded to the jail as Castro continued to shoot, according to a press release from the Santa Clara County Sheriff’s Office.

After a nearly four hour stand-off, Castro surrendered and was taken into custody at 5:48 a.m.

Castro now faces charges of attempted murder, assault with a deadly weapon and taking a peace officer’s firearm in addition to the charges he’d already been arrested on.

“The officer did follow all the protocol and safety measures to secure his weapon,” said Low.

MORE NEWS: Belt, Gausman Lead Giants and Kapler Over Phillies 2-0

Anyone with knowledge of the case are advised to contact the Investigative Services Division at the sheriff’s office at (408) 808-4500. Tipsters can also contact the office anonymously at (408) 808-4431.