A U. S. District Court judge in Baltimore ruled yesterday that an Eastern Shore tank farm containing thousands of gallons of deadly chemicals belongs to William R. Grigby, who originally brought the tanks to the small community of Sharptown.

The order by Judge James R. Miller Jr. also noted that the presence of both highly flammable and cancer-causing chemicals in the tanks "constitutes a severe health threat to the immediate environments and therefore requires immediate removal."

But the judge's order does not specifically direct anyone to remove the dangerous chemicals and appeared to complicate the already tangled process for disposing of them.

On the one hand, J. L. Hearn of the Maryland Division of Water Resources said yesterday that "the judge has found Mr. Grigsby is responsible for the removal" of the chemicals.

But Grigsby, reached at the headquarters of Grigco Waste Oil Services near Dover, Del., said he would handle the disposal only if he determined "that they are my materials in those tanks."

If Grigsby refuses, in his words, to "clean up somebody else's mess," the responsibility for removal of the chemicals falls on the Coast Guard, which is empowered to handle clean-up operations in situations that represent an "immediate danger" to coastal waters.

To date, Coast Guard officials have stopped some minor leaks at the facility along the shore of the Nanticoke River, repaired the surrounding fence and tested samples taken from the tanks, but have refused to designate the 39 tanks an immediate hazard.

"It's not the Coast Guard's responsibility for the removal of (the chemicals) under these circumstances," said Coast Guard Capt. J. William Kime. ". . . There is no immediate threat to water pollution or to public safety and health in the immediate area," he said.

Ralph Cordrey, the 35-year-old mayor of Sharptown, a onetime shipbuilding community with a population of 670, said yesterday that "now the ownership has been determined, all these government organizations should stop jawing about it and get the stuff out."

Laboratory tests for the Coast Guard, the Environmental Protection Agency and the Maryland Department of Natural Resources in the last month have determined that the tanks contain substantial amounts of benzene, which has been shown to cause leukemia in humans, and the highly flammable solvent xylene.

In addition, one tank contains at least 7,000 gallons of waste oil contaminated with the highly toxic material PCB, a powerful cancer-causing agent that is virtually indestructible.

The tank farm was built by Grigsby in 1971 as part of a waste-oil reprocessing plant. The plant operated for a few months in 1974 and 1975 before state officials revoked Grigsby's license to store waste oil, saying he had failed to complete the safety procedures required to prevent spills.

In an interview earlier this week, Gigsby denied that any benzene, xylene, or PCB were in the tanks when he lost control of the property in 1978. The Small Business Administration took control of the property that year after Grigsby defaulted on a $270,000 SBA-INSURED loan.

he SBA then tried to sell the property at auction, but the first buyer, a firm called Petrol Recycling Corp. defaulted. In March, the property was again sold, this time to Delmarva Waste Oil Corp., which handed over a $5,400 down payment.

Shortly after the sale, Grigsby informed the Maryland natural resources agency that the tanks contained not just waste oil, but also solvents, phenyl compounds and other contaminants, according to state agency official Thomas Boone.

When the presence of the contaminants was confirmed last month, the owner of the Delmarva firm went to federal court to block ratification of the sale. In his ruling yesterday, Judge Miller, acting on the recommendations of Magistrate Daniel E. Klein Jr., upheld Delmarva's position.

"This has been one can of worms," Environmental Protection Agency official Howard Lam'l said yesterday. The chemicals in the tank farm, while not leaking at the moment, "could become overnight a very real emergency," he added.

"But right now we've got other problems to deal with which are imminent hazards to people."

No disposal of the Sharptown wastes can be considered he added, until testing is complete and the contents of all the tanks have been identified, a process that will take at least another week. In addition, the Coast Guard, the EPA and the Maryland natural resources agency are trying to find a location where the PCB-contaminated oil can be safely buried.

When the testing is complete, said Hearn, who heads the enforcement program for the water resources division of the Maryland agency, federal and state officials will reassess the situation to determine if the tanks represent an immediate threat.

Michael Wilkinson, an aide to Rep. Robert Bauman (R-Md.), who represents the Eastern Shore, said yesterday Bauman is strongly requesting the Coast Guard to take charge of the disposal and remore the chemicals as soon as possible.

Washington Post special correspondent Chris Schauble contributed to this story.