Following their arrest on firearm and drug charges, the defendants, William A. Graham and Robert Kines, moved to suppress the incriminating evidence, which consisted of *128marijuana found in their pockets and a pistol foi nd in the glove compartment of the automobile Kines was driving when police stopped it for traffic violations. A judge allowed the defendants’ motion and the Commonwealth appeals, but only from suppression of the firearm.
We take the pertinent facts from the judge’s findings. Commonwealth v. Washington, 449 Mass. 476, 477 (2007). On those facts, the motion judge found that the exit orders were warranted, but that the officers illegally searched the vehicle’s passenger compartment and locked glove box. He also found that the officers had illegally searched the defendants’ pockets because their preliminary patfrisk of the exterior of the pockets had not produced anything they recognized as a weapon or contraband.
In appealing suppression of the firearm, the Commonwealth argues, among other things,2 that the search of the glove box was justified by a reasonable concern for officer safety We agree.
When they first observed the defendants’ vehicle, the officers were patrolling a section of Boston in response to recent firearms problems that included a shooting. The officers' attention had been drawn to the defendants when the officers saw a group of people on a sidewalk shrink back and away as the defendants’ vehicle slowed while passing them. After stopping the vehicle for traffic violations, the existence of which no one challenges, the officers became aware that a rear seat passenger had a history of firearm-related offenses. Moreover, the officers thought that all of the vehicle’s passengers, whom they knew were associated with members of a local gang, “might be involved in firearm related activity.” In addition, one of the officers had seen Kines, the driver, lock the glove compartment after retrieving the registration and heard him express concern about leaving his keys behind after he got out of the vehicle. The exit order had been prompted by Kines’s refusal to stop reaching down between the seat and the center console after one of the officers told him to keep his hands in sight. A patfrisk of Kines turned up a knife clipped to the side of his jeans and four baggies officers believed *129contained marijuana. The initial patfrisk of Graham revealed a knife concealed in a sheath inside his waistband. Finally, the officers did not arrest the rear seat passenger whom they knew had been associated with firearms and who surely would have had access to the glove box key Kines had left on the driver’s seat when he was taken into custody. Taken together, those circumstances were sufficient to give the officers a reasonable concern for their own safety.
The officers’ reasonable concern for safety, in turn, permitted a Terry-type search of the vehicle’s interior. See Terry v. Ohio, 392 U.S. 1 (1968). See also Commonwealth v. Pena, 69 Mass. App. Ct. 713, 718 (2007), quoting from Commonwealth v. Silva, 366 Mass. 402, 406 (1974) (search of an automobile is permissible if police are “warranted in the belief that the[ir] safety . . . or that of other persons was in danger”). See generally Commonwealth v. Lopes, 455 Mass. 147, 161 (2009). That concern was not limited to what the occupants might do while under the officers’ immediate control. Instead it extended to threats that might arise from retrieval of a weapon in the vehicle by an occupant who was not placed under arrest. See Commonwealth v. Santiago, 53 Mass. App. Ct. 567, 571-572 (2002); Pena, supra at 719. See generally Michigan v. Long, 463 U.S. 1032, 1051 (1983) (“In this case, the officers did not act unreasonably in [searching the interior of a stopped vehicle] to ensure that there were no other weapons within [the defendant’s] immediate grasp before permitting him to reenter his automobile”); Commonwealth v. Lantigua, 38 Mass. App. Ct. 526, 528 (1995) (“[P]rior to allowing the defendant to reenter the car to obtain the registration, the officers could properly effect a Terry-type search of the areas of the car which would be readily accessible to the defendant on reentering”).
Contrary to the defendants’ argument, the police did not exceed the scope of a permissible protective search by opening the locked glove compartment. The protective search must be limited to what is minimally necessary to dispel safety concerns, and “ ‘confined in scope to an intrusion reasonably designed to discover’ a weapon.” Commonwealth v. Moses, 408 Mass. 136, 144 (1990), quoting from Silva, supra at 408. If safety concerns necessitate doing so, police may open a closed container. See Commonwealth v. Pagan, 440 Mass. 62, 72-73 (2003) (“[I]f the *130container is such that a patfrisk might suffice to establish that there is no potential weapon within, the container may not be opened as part of a search for weapons unless a patfrisk has first been performed. If, however, a patfrisk would not suffice to dispel suspicion and avert the need for a search, no patfrisk need be performed. In each case, the method and scope of an officer’s search for reasonably suspected weapons must be confined to what is minimally necessary to discover the presence or confirm the absence of a weapon”). The glove compartment, which Kines had locked as police approached the car, was large enough to contain a weapon. The keys remained in the vehicle, accessible to any passenger the police released. Under those circumstances, police were entitled to open the glove compartment for the limited purpose of determining whether it contained a weapon.
We likewise reject the defendants’ argument that there was no basis for the exit order. To be sure, “[wjhen the police are justified in stopping an automobile for a routine traffic violation, they may, for their safety and the safety of the public, order the driver or the passengers to leave the automobile, but only if they have a reasonable belief that their safety, or the safety of others, is in danger.” Commonwealth v. Torres, 433 Mass. 669, 673 (2001), citing Commonwealth v. Gonsalves, 429 Mass. 658, 662-663 (1999). In this case, the exit order was justified by essentially the same facts that justified the search of the vehicle’s interior. Indeed, the only new information police obtained after the occupants left the vehicle was that Graham had a knife hidden in his waistband.
Insofar as the order required suppression of the firearm discovered in the glove compartment, the order is reversed. In all other respects, the order is affirmed.
So ordered.
The Commonwealth asserts that Graham had not properly established an expectation of privacy in the contents of the glove compartment. Because we dispose of the case on other grounds, we need not address this argument.