If the sand around the eggs hits 30 degrees Celsius (86 degrees Fahrenheit), the gender balance shifts to females, Mr. Drews said, and at about 32 degrees (89.6 Fahrenheit) they are all female. Above 34 (93), “you get boiled eggs,” he said.

Image At a beach there, boys prepared to release hatched turtles. Credit... Ruth Fremson/The New York Times

On some nesting beaches, scientists are artificially cooling nests with shade or irrigation and trying to protect broader areas of coastal property from development to ensure that turtles have a place to nest as the seas rise.

In places like Playa Junquillal, an hour south of here, local youths are paid $2 a night to scoop up newly laid eggs and move them to a hatchery where they are shaded and irrigated to maintain a nest temperature of 29.7 degrees Celsius (85.4), which will yield both genders.

On a recent night, Dennis Gómez Jiménez, a 22-year-old in a red baseball cap and jeans, deftly excavated the nest of a three-foot-wide Olive Ridley, one of the smaller sea turtle species. The turtle had just finished the hourlong task of burying 100-plus eggs and then lumbered back into the water.

One by one, Mr. Jiménez placed what looked like table tennis balls into a plastic bag and transferred them to an ersatz nest he had dug in a shaded, fenced-off portion of sand that serves as a hatchery. Sandbags are positioned to protect against tides that could rip nests apart.

When the turtles hatch, in 40 to 60 days depending on the species, they are carried in wicker baskets to the ocean’s edge and make a beeline for the water. Gabriel Francia, a biologist who oversees the youths, known locally as the “baula” or leatherback boys, likens their work to delivering an endangered infant by Caesarean section.