Federal lawmakers are considering the broadest effort ever to limit what children eat: a national ban on selling candy, sugary soda and salty, fatty food in school snack bars, vending machines and à la carte cafeteria lines.

Whether the measure, an amendment to the farm bill, can survive the convoluted politics that have bogged down that legislation in the Senate is one issue. Whether it can survive the battle among factions in the fight to improve school food is another.

Senator Tom Harkin, Democrat of Iowa and the chairman of the Agriculture Committee, has twice introduced bills to deal with foods other than the standard school lunch, which is regulated by Department of Agriculture.

Several lawmakers and advocates for changes in school food believe that an amendment to the $286 billion farm bill is the best chance to get control of the mountain of high-calorie snacks and sodas available to schoolchildren. Even if the farm bill does not pass, Mr. Harkin and Senator Lisa Murkowski, Republican of Alaska, a sponsor of the amendment, vow to keep reintroducing it in other forms until it sticks.