This is the story of the worm that could shut down the Port of New York. It also involves the idea of covering every vacant lot in the city with eight inches of fertilizer in which food must never grow. It is, in short, another chapter in the saga of the toilet training of America.

For years the nation has treated the ocean as its septic tank. Now federal law requires an end to that, but the problem of what else to do with all the sewage and garbage and silt and other unpleasant material has not been solved.

For New York, the most pressing problem is the harbor.

The Hudson River brings vast quantities of silt into the harbor every day, and dredges must work constantly to keep the channels navigable. Since 1927, the dredged material, called spoil, has been barged 12 miles out to sea and dumped in an area called the New York Bight.

Last year, 10 million cubic yards were dumped, enough to fill the Empire State Building 20 times.

But last fall, the Environmental Protection Agency discovered that when sample material from the harbor bottom was fed to certain types of sea worms the worms picked up significiant quantities of a toxic chemical CALLED POLYCHLORINATED BIPHENYL (PCB).

So in October the agency concluded that parts of the harbor bottom are so polluted that material then could no longer be dumped at sea.

But without dredging, the harbor would return to an average depth of 18 feet, not nearly deep enough for most of its traffic.

"In order for this to be solved in the long run, everyone involved in the harbor has to look for land-based alternatives to dumping this stuff in the ocean," said James R. Marshall, director of external programs at EPA's New York office. "Things like old quarries, or old pits already in the harbor."

Unfortunately, most of those old quarries may have to be filled with sewage sludge instead.

Congress in 1977 ordered New York and the rest of the country to stop dumping sewage sludge in the ocean by Dec. 31, 1981. "Land-based alternatives" must be found now for the sludge as well as for the dredging spoils.

Heavy barges load up every day in New York with 8,300 tons of smelly, thick black sludge and take it six miles out to sea for dumping in another part of the New York Bight.

Composed of digested sewage, stormwater runoff, and processed garbage, the sludge has been poured for 44 years into a 6 1/2-square-mile area and has gradually spread to form what EPA has called "a 25-square-mile dead sea."

In that area, the teeming life of the ocean is absent. What fish there are suffer from fin rot and black gill disease; many are deformed. Shellfish are diseased, and strange amoebas exist. There are mercury, DDT, PCBs and dangerous bacteria, but most of all there is cadmium.

Cadmium, a heavy metal associated with kidney and liver diseases, is left on city streets as tires wear. Washed into storm sewers and into the sludge, it is unaffected by any sewage treatment.

New York's proposal to deal with the sludge on land involves eventual conversion of it to compost, a soil conditioner that has long been used on farms and gardens nationwide. But cadmium makes compost dangerous for crops, since it is taken up into leaves of plants.

Nobody wants New York's proposed compost because of the high levels of cadmium that would be in it. So the city has to dispose of the compost.

In recent testimony before Congress, Commissioner Frank McArdle of New York's Department of Environmental Protection said, "The land on which sludge compost is spread may never be used for any agricultural purpose whatsoever." Instead, he said, the city would put 500 tons of it on every acre of unused land undeveloped park and old landfill in the five boroughs.

But after five years, when all the land is covered 8 inches deep with composted sludge, where does the next day's output go? And when the quarries are filled, where will the dredging spoil be put?

The House Merchant Marine and Fisheries Committee holds hearings today to discuss one answer to the dredging problem, and another hearing Wednesday on a possible solution to the sludge standard by which the problem is defined.

"We don't want to create a greater environmental hazard on the shore than we have in the ocean," said Rep. John M. Murphy (D-N.Y.), chairman of the committee.

A proposal by Rep. Peter A. Peyser (D-N.Y.) would suspend for two years the use of tests on worms and other sea animals. His amendment to the 1972 Ocean Dumping Act, backed by other New York members of Congress, would require the EPA to study the tests until 1982 to determine whether they show the impact of pollutants on humans.

The National Wildlife, Federation has pledged to fight the amendment. "Tests are not the source of the problems; contamination of the dredge material is the source," said Kenneth Kamlet, the federation's assistant director. Recent modifications of the tests, agreed to this week, loosen the results too much, he said.

Murphy said he plans to offer another ocean dumping law amendment next week to deal with the sludge problem. It would direct the EPA to study the effects of dumping the cadmium-rich compost on land to see whether the result might be more dangerous than putting the sludge in the ocean.

"We can't throw it into outer space. It's our creation, so what do we do with it? Where is the least risk?" Murphy asked.

EPA's Marshall said athe agency would oppose both changes. "There is damage at the dumpsite. Land-based alternatives have been thoroughly demonstrated elsewhere . . . we've had enough testing."