Last Tuesday Gary Spangler was working at the naval air station here, helping the United States keep watch on the allegedly hostile shores of Cuba 90 miles away.

The next day he and three other Navy officers climbed aboard his brown-and-white 44-foot sloop and sailed with 30 other boats to those same Cuban shores for Thanksgiving. Lt. Spangler even brought along his mother.

The occasions was the second annual Key West-Varadero Yacht Race, an improbable human venture in international relations which promises to produce the first open access to Cuba by U.S. vessels since Fidel Castro's early days 20 years ago.

Like so many great Caribbean endeavors, the race was dreamed up amid the Polynesian inspiration of Key West's Hukilau bar. It is the product of a socialist yachtsman in the Cuban Institute of Tourism and a handful of laid-back Key West sailors weary of politics getting in the way of fun.

And it may tell more about the state of Cuban-American dialogue than the Navy's Joint Carribean Task Force now taking form at the naval air station northeast of Key West. Neither the U.S. government nor the Cuban government apparently saw anything unusual about a yacht race between two countries that technically do not recognize one another's existence.

Neither did the dozens of military participants, active and retired, most of whom at some time have been involved in at least subtle efforts either to frustrate or monitor Fidel Castro's socialist experiment.

"We don't worry down here about Fidel; him we can handle," said Dean Payne, the 57-year-old Navy commander-turned-sailmaker, who five years ago headed the classified Key West Communications Center. "All we worry about is (President) Carter.'

"You know how much trouble we've had getting clearance to come here? None at all," Lt. Scott Davis, an active duty flight officer, said in Havanna after the race. "I just filled out a form. There's nothing political about this race. It's just something with the local yacht club."

Actually it involves a lot more than that, including Cuban visa clearance for more than 150 yacht owners and members from as far away as Washington, D.C., Cuban operation of the finish line off the north coastal resort community of Varadero -- 70 miles east of Havana -- and dozens of other arrangements radical for a government still struggling with such tourist facts of life as a traveler's check.

But before it was over, the Cubans were selling on credit, renting cars for tours of the island's interior and promising that any yachtsman who returned would be able with advance notice, to cruise almost unrestricted in Cuba's network of coves and beaches.

"We want this very much and we are working on it," Armando Valdes, an executive with Cuban Institute of Tourism. "Immigration and customs have some problems with it but we think we can work it out."

Vincente de la Guardia, 45, director of the tourism institute, said Cuba has begun making nautical charts available and permitting yachtsmen to cruise the 3,000 miles of shoreline, if they clear their itineraries and timetables with the Cuban government.

But the days of Cuban gunboats confiscating yachts are not long past and some tensions remain.

One Yacht captain returned from Friday night's awards banquet to his vessel at the marina to find a would be refugee huddled in his sail locker, begging to be smuggled to the United States. The captain turned him down and sent him quietly back over the side.

"It was the only thing he could do," said one race official. "We couldn't risk any incident."

The Key West-to-Varadero race was born late year when La Guardia wandered into Key West on a U.S. authorized search for Americans interested in staging a fishing tournament in Cuban waters.

He ran into a tatooed Key West perennial named Carl Rongo in the Hukilau.

"One drink led to another as I recall," Rongo said, "and we said the hell with fishing, what about an offshore race."

La Guardia, a tanned and charismatic man, needed no second urging.

A member of the exclusive Havana Yacht Club in the pre-Castro days, he remembers finishing first in 1959 aboard the club's 67-foot cutter Lomo del Mar in the last St. Petersburg-to-Havana race -- once a premier feature of the international ocean racing circuit.

He returned to Havana and, with the help of his new friend in Key West, frantically threw together arrangements for an overnight race of 60 vessels which Sail magazine dubbed, "Night flight to Cuba."

"It was really wierd going down there," remembers Roland Parker, 40, a retired Navy corpsman whose 51-foot Morgan finished second last year.

"We wondered if it would be dangerous . . . . But in the end I even took the kids and their bicycles."

Parker's apprehensions were not eased when Cuban frogmen checked the yacht's hulls as they passed the fading pre-Casrtro mansions of Varadero's ocean front.

"But once we got there the Cubans couldn't do enough for us," Parker said. "They opened up everything. I wouldn't have missed this year for anything." Neither would the Cubans, who by some calculations made more than $30,000 from the yachtsmen in about three days.

This year, when notice of the race went out, the club was deluged with 150 applications. But after the flurry of publicity over a Soviet brigade in Cuba and President Carter's Oct. 1 speech on the subject, less than one-third of the applications were returned.

Peter Heidenberger, a 57-year-old Washington lawyer, was one of those who entered. "We were bringing the boat down to Vero Beach anyway," he said, "so we thought, 'Well, why not' But people in Washington kept telling me I was crazy. You're going where?' they said. They couldn't believe it." m

Those who came found the Cubans less of a problem than the 35-knot easterly winds, four-knot westerly current and 10- to 15-foot seas that shredded sails, splintered rigging and nearly sank one boat.

At Varadero they found the Cubans eager to help, more flexible with regulations and promising access to coastline they had denied before.

"I hope it all happens," said Mike Huffman, a 31-year-old Navy helicopter pilot sailing his second race to Varadero. "I'm not wild about their government but the Cuban people are beutiful and the coastline is just incredible."

As for the Key West-to-Varadero race, that seems sure to continue, occasionally even turning political rough spots into unlikely assets.

"Last year there was a big flyover while we were in Havana," Huffman said. "The Navy jet pilots on the race thought that was better than sex."