What Are Crypto Sandwich Bots?
A sandwich bot places trades around your trade to profit from the price move it causes. Learn how it works, why it targets some trades, and how to stop it.
On this page
Short answer
A crypto sandwich bot is an automated program that watches pending trades, buys a token before a large trade, lets that trade push the price up, and then sells at a profit. It works on decentralised exchanges where pending trades are public, and it earns the gap between its buy and sell prices minus network fees.
What is a crypto sandwich bot?
A crypto sandwich bot is an automated program that places its own trades around another person's trade to profit from the price move that trade causes. The victim's trade is the filling, and the bot's two trades are the slices of bread on either side.
It works on decentralised exchanges, where pending trades sit in a public waiting area called the mempool before they are confirmed. A bot watches the mempool for a large buy order, buys the same token first so the price rises, lets the victim buy at the higher price, and then sells its own tokens at a profit.
| Step | What happens | Who gains |
|---|---|---|
| 1. Front-run | Bot buys the token before the victim | Bot, from the lower price |
| 2. Victim trade | Victim buys, pushing the price higher | Nobody, the victim pays more |
| 3. Back-run | Bot sells its tokens at the higher price | Bot, from the price gap |
The bot earns the difference between its buy price and its sell price, minus the network fees it paid to get its trades confirmed in the right order. Sandwich bots are a form of MEV, or maximal extractable value, which is the value that can be taken by choosing the order of transactions in a block.
How does a sandwich attack work, step by step?
A sandwich attack works because pending trades are visible before they are confirmed, and because a large trade moves the price on a decentralised exchange. The bot needs three things: a pending trade worth targeting, enough capital to buy first, and a way to pay for priority in the block.
- Watch the mempool. The bot scans pending trades for a large swap on a token pair with a thin pool, where a single trade will move the price noticeably.
- Front-run the trade. The bot submits a buy of the same token, paying a higher network fee so its trade is confirmed first.
- The victim trade executes. The victim's swap runs against a pool that now holds fewer tokens, so the victim receives fewer tokens than expected.
- Back-run the trade. The bot sells the tokens it just bought, again paying for priority, and pockets the difference.
- Repeat. The bot runs this loop all day, scanning for the next large pending trade.
The whole attack happens inside a single block, often within seconds. The victim rarely notices at the time, because the trade still completes, just at a worse price than the quote they saw. What is a DEX explains how decentralised exchanges set prices from pools, which is what makes the price move possible.
What is MEV, and how do sandwich bots fit in?
MEV, or maximal extractable value, is the extra value that can be captured by choosing which transactions go into a block and in what order. Sandwich bots are one of the best-known ways to capture it, alongside arbitrage bots and liquidation bots.
Arbitrage bots profit from price differences between exchanges, and liquidation bots profit from closing under-collateralised loans. Sandwich bots are different because they profit directly from another trader's order, which is why traders dislike them more than the other kinds.
MEV exists because block builders decide the order of transactions, and that order has real money attached to it. Some chains and tools now try to share MEV more fairly or hide pending trades, but as long as trades are public before confirmation, sandwich bots have something to work with.
It is worth noting that not every fast trade is a sandwich. Market makers and arbitrage bots also trade quickly, and they usually improve prices rather than worsening them. A sandwich is defined by its structure: a trade placed around someone else's trade to profit from the move it causes.
Why do sandwich bots target some trades and not others?
Sandwich bots target trades where the profit covers the cost of front-running and back-running. A trade is worth targeting when it is large, when the token pool is thin, and when the trader has set a generous slippage limit.
- Large trade size. A swap worth thousands of dollars moves the price more than a small swap, so the bot's profit is larger.
- Thin liquidity. A pool with little money in it moves a lot on a single trade, which gives the bot a bigger price gap to sell into.
- High slippage tolerance. Slippage is how much worse than the quoted price a trader will accept. A high limit, such as 5 percent, gives the bot room to push the price and still have the victim's trade go through.
- Popular tokens. Bots watch the busiest pairs, where large trades appear often, rather than obscure tokens with little activity.
Small trades on deep pools are rarely worth sandwiching, because the price barely moves and the network fees eat the profit. That is why most everyday swaps are never targeted, while a large swap on a new or thinly traded token often is. What is Ethereum covers the network where most sandwich activity happens.
How can traders protect themselves from sandwich bots?
Traders protect themselves from sandwich bots by making their trades harder to profit from: smaller trades, tighter slippage limits, and routes that hide the trade from the public mempool.
- Set a tight slippage limit. A limit of 0.5 percent or less leaves little room for a bot to push the price, and the trade will fail rather than execute at a bad price.
- Split large trades. Breaking one large swap into several smaller ones reduces the price move each trade causes, which shrinks the bot's profit.
- Use private transaction routes. Some wallets and services send trades directly to block builders instead of the public mempool, so bots never see them.
- Trade on deep pools. A pool with a lot of liquidity barely moves on a single trade, which makes sandwiching unprofitable.
- Check the quote before confirming. If the expected output looks worse than the price you saw a minute ago, wait or re-quote.
Private routes are the strongest protection, but they are not available everywhere. For most traders, the practical combination is tight slippage plus splitting large trades. Smart contract development covers how exchange contracts are built, including the settings that control slippage.
Example (hypothetical): a sandwich on a token swap
Example (hypothetical): a trader wants to swap 10 ETH for a new token priced at $1.00. The pool is thin, and the trader sets a slippage limit of 5 percent, so the trade will go through even if the price moves a lot.
A bot spots the pending trade. It buys 5,000 tokens first at an average price of $1.02, spending $5,100. The victim's trade then executes at a worse price, pushing the token to $1.04. The bot sells its 5,000 tokens at $1.03, receiving $5,150. That is $50 of gross profit. The bot paid $12 in network fees for its two trades, so its net profit is $38.
The victim, meanwhile, receives fewer tokens than the quote promised. If the victim had set a slippage limit of 0.5 percent, the trade would have failed instead of executing at the pushed price, and the bot would have lost its fees. If the victim had split the swap into five smaller trades, each one would have moved the price less, and the bot's profit would have been too small to bother.
The numbers show why bots prefer thin pools and large trades. On a deep pool, the same 10 ETH swap would move the price by a fraction of a cent, and the bot's $38 profit would turn into a loss after fees.
What are the common mistakes?
The most common mistakes are setting slippage too high, trading large amounts on thin pools, and assuming that a completed trade was a fair trade.
- Leaving slippage at the default. Some interfaces default to 5 percent or more. Lower it for every trade, especially on new tokens.
- Swapping a large amount in one trade. One big trade is the easiest target. Split it, or trade on a deeper pool.
- Trading new tokens at market price. New tokens have thin pools and volatile prices, which is where bots are most active.
- Ignoring the quote. If the output you receive is clearly worse than the quote, something moved the price. Check before you trade again.
- Assuming all fast trading is a sandwich. Arbitrage and market making also move fast, and they usually help prices. Look for the pattern, not the speed.
Sandwich bots are a cost of trading on public, decentralised markets, but they are avoidable. Tight slippage, split trades and private routes take away most of the profit, and bots move on to easier targets. For the exchange side of the picture, DeFi development covers how decentralised trading systems are built.
Key takeaways
- A sandwich bot buys before your trade and sells after it, profiting from the price move your trade causes
- Sandwich bots work because pending trades are visible in the mempool before they are confirmed
- Large trades on thin pools with high slippage limits are the easiest targets
- Tight slippage, split trades and private transaction routes take away most of the bot's profit
- A trade that completes is not proof it was fair: compare what you received with the quote
Frequently asked questions
Is a sandwich bot illegal?
There is no single answer, because rules differ by place and are still developing. Sandwich trading is widely seen as unfair to traders, and some regulators and exchanges treat it as market manipulation, but enforcement varies. Treat it as a risk to manage rather than a legal question you can settle by reading one article.
How do I know if I was sandwiched?
Compare the tokens you received with the quote you saw before confirming. If you received clearly fewer tokens and the price moved sharply during your trade, a sandwich is a likely cause. Block explorers can show the trades confirmed just before and after yours in the same block.
What is the difference between a sandwich bot and an arbitrage bot?
An arbitrage bot profits from price differences between two exchanges and usually brings prices closer together, which helps traders. A sandwich bot profits by trading around your order and making your price worse. The first improves the market; the second takes value from a specific trader.
Does slippage protection stop sandwich bots?
Tight slippage limits help a lot, because the victim's trade will fail instead of executing at a pushed price. But slippage alone is not a full fix: a bot can still front-run a trade that goes through within the limit. Combining tight slippage with split trades or a private route is stronger.
Can sandwich bots work on centralised exchanges?
No, not in the same way. Centralised exchanges keep their order books private, so bots cannot see your pending order and trade around it. Sandwiching is a feature of public mempools on decentralised exchanges, where pending trades are visible to everyone.
Are all crypto trading bots sandwich bots?
No. Most trading bots do other jobs: market making, arbitrage, portfolio rebalancing, or running a set strategy for their owner. Sandwich bots are a specific kind that profits from other traders' orders, and they are a small share of all automated trading.