Authorities said no classes or groups were meeting in Boulder High School at the time. Police sealed off the building, and school officials canceled classes for the day.
The initial search by a dozen officers and a bomb-sniffing dog turned up nothing. There was no immediate word on the results of a second, more thorough search by a SWAT team. That search included utility-access tunnels under the building, Police Chief Mark Beckner said.
Beckner said there was no indication the intruders were armed.
"This could be a spring, end-of-school-year prank. It could be a burglary. It could be kids goofing around, or it could be more serious," Beckner said. "Given the times that we live in and recent events, we have to take all precautions."
Beckner said the cook spotted the men around 6 a.m. on the first floor of the three-story building, and that they ran when she yelled at them. She described them as young but was unable to describe their faces, Beckner said.
Chris King, deputy superintendent of the Boulder Valley School District, said all the doors should have been locked then, and the school's alarm system hadn't gone off overnight. The only employees known to have been inside were the cook and two custodians, who customarily disarm the system when they arrive.
King said authorities would review recordings from 15 surveillance cameras around the outside of the school, but there are no cameras inside.
At a nearby snowboard shop, Boulder High freshman Jake Hanifin, 15, and his friends said the incident didn't sound like a prank.
"I think it's hard to believe it's a joke if a kid comes in with a ski mask," he said. "To push a joke to that limit would be pretty intense."
No threats had been made against the 1,900-student school in recent days, the police chief said. Earlier this spring, graffiti had been found inside the building saying people would die on April 19, the day before the anniversary of the Columbine High School shootings near Denver. Classes were held that day with extra security, he said.
The University of Colorado alerted students, faculty and staff on parts of the campus near the high school, but no classes or other activities were interrupted, the university said.