“Now, I don’t want anybody getting in trouble now that you know how to use this puppy,” Darrell Andrews, one of the camp’s instructors, warned loudly. “Right? Right?” he added with emphasis.

As campers around the country sleep under the stars and dive into mountain lakes, 1,400 youths have packed their overnight bags or lunchboxes for a very different experience.

They are attending dozens of free overnight and day camps across the country supported by the N.S.A., better known for its bulk collection of Americans’ phone records and its spying on foreign leaders. Like the C.I.A. and other elite intelligence agencies, the N.S.A. has for decades recruited on college campuses and run collegiate programs, but this summer the agency is making sure that middle- and high-school-age students — and some teachers, too — are learning how to hack, crack and defend in cyberspace.

The goal of GenCyber, as the summer camp program is called, is to catch the attention of potential cybersecurity recruits and seed interest in an exploding field as more and more of the nation’s critical transactions, from warfare to banking, move into the realm of cyberspace.

N.S.A. officials say building the next generation’s cyberspace work force is a matter of national security, as a string of massive breaches at the federal Office of Personnel Management and private companies have highlighted. Studies anticipate the need to fill hundreds of thousands of new cybersecurity jobs in coming years.