A sandwich attack is a way of profiting from someone else's trade on a decentralised exchange. On public blockchains, pending transactions wait in the mempool where anyone can see them. A bot spots a large swap that will push a token's price up, places its own buy just ahead of it, lets the victim's trade execute at the worse price, and then sells straight after. The victim's trade is "sandwiched" between the two, and the bot keeps the difference minus fees.
It is a blockchain form of front-running and one of the main sources of maximal extractable value (MEV). It works because automated market makers move prices predictably with trade size. The main defence is a tight slippage tolerance, which makes the swap fail if the price moves too far. Splitting large trades, private transaction relays and other MEV protection services also reduce exposure.
Ref 1140000190