A high-stakes race between the United States and the Soviet Union is shaping up on the seas and in law offices in the search to find the "black box" in-flight data recorder that lies somewhere in the Sea of Japan, in the wreckage of the downed South Korean airliner.

While ships and planes of the United States, Japan and the Soviet Union search for the wreckage of Flight 007, lawyers at the State Department are preparing paper work that will legally designate the United States and Japan as the search and salvage agents for South Korea.

Sources here said that the South Korean government made such a designation last week and that the Reagan administration is preparing the documentation that will be sent to Seoul to complete the arrangement.

In practical terms, if the wreckage is found, the question of who gets lines on it first and hauls it into custody may turn on a display of naval muscle by either side.

But as U.S. officials explain it, the arrangements now being worked out between South Korea, Japan and the United States are crucial from a legal standpoint, especially if the wreckage is found in international waters.

The South Koreans have claimed essentially that the downed aircraft remains their property and is not abandoned. This takes away the legal right of other countries such as the Soviet Union to grapple for it as a country or a private party might do for a sunken craft that has been abandoned. The Seoul government now has also given Japan and the United States permission to "touch" and thereby recover its property for Korea.

What would happen if the wreckage is found in international waters and the Soviets go for it and retrieve it would be "a very tricky situation," according to one official, raising questions of whether force could or would be legally permissible to prevent that from happening.

Both the United States and the Soviet Union now have vessels in the area capable of sending down small submersibles to try to get lines on and retrieve the wreckage if it is located. The waters in the region are about 900 to 1,200 feet deep, officials said.

American officials also said that South Korean officers are serving aboard U.S. vessels to help in the search.

Officials here said they believe that the wreckage of the plane, or at least parts of it, "should be in international waters, but just barely," meaning that it probably lies extremely close to Soviet waters just off the Soviet island of Sakhalin.

The administration already has raised the possibility in public statements that the jetliner may have been shot down just as it passed out of Soviet airspace, rather than when it was clearly inside Soviet airspace, as the Soviet air defense command rushed to deal with the aircraft before it escaped.

About two dozen Soviet vessels are patrolling in international waters as well as their own, but the Moscow government will not allow the American and Japanese craft to search in Soviet waters. The Soviets claim a 12-mile zone off their coast as their territorial waters.

Officials said that if the Soviets found the wreckage in their waters Moscow would probably claim "certain rights," but they gave no indication that the West would relinquish its legal claim.

Although the Soviet vessels on one or two occasions have rendezvoused near a specific area, U.S. officials said yesterday there is no evidence that the Soviets have located anything on the sea bottom.

The race for the black box is potentially crucial for several reasons.

It could hold clues explaining how the Korean Air Lines jumbo jet with 269 persons aboard strayed hundreds of miles off course and into Soviet airspace before being shot down near Sakhalin by Soviet fighter pilots 16 days ago.

The black box could also contain cockpit conversation not recorded by ground stations that could reveal if the airliner pilots had any indication that they were in trouble prior to being hit by Soviet heat-seeking missiles.

The United States is also particularly anxious not to have the Soviets get to the wreckage first because of fears, as stated by several officials yesterday, that Moscow will try to somehow falsify either documents or the black box to back up Soviet allegations that the plane, which flew over or near sensitive military installations, was on a spy mission. South Korea has denied that it was using the plane for espionage purposes.

The black box actually is painted orange to facilitate recovery and gives off an electronic beep that is also supposed to aid searchers.

This beep is supposed to last for a month, but some sources yesterday suggested that if the beeper is going it may not last much longer.

The U.S. Navy now has an ocean-going tugboat, the 2,400-ton Narragansett, and a salvage vessel, the 2,000-ton Conserver, that in combination are equipped to detect the beeper and deploy a robot-like submersible to retrieve wreckage.

Aside from these vessels, the United States has a destroyer, frigate and Coast Guard cutter in the region, as well as HC130, P3 and airborne warning and control system (AWACS) patrol planes.