Lmao, somebody must've Bokurolled you A2. This fight's always rather exciting for me. You just can't let them run around.
Best tools vs Sonic are Ftilt, fireball, and SHNair. All 3 are good at keeping his spindash at bay; fireball stops it and Ftilt/Nair plow right through. This particular insanely iconic pairing is pretty even in the sense that neither party can play the way they normally would vs the other. Mario can thoroughly keep Sonic's approaches predictable with fireballs/Nairs/Ftilts, and they rack up damage at generally the same speed. We also kill a fair bit earlier with Fsmash and Usmash. Keep your Usmash fresh. I cannot stress this enough. Having a fresh Usmash is like having a full bucket for oil panic in this matchup. Usmash eats right though most of Sonic's attacks and is about as fast. It'll also be killing around 130-140%.
On the other white-gloved five-fingered hand, we have Sonic who will rarely be gimped but will actually be the gimp artist in this matchup because of his insane recovery. Spring will usually be a successful gimp if your second jump is gone, but if you conserve your recovery options, it shouldn't be too big a deal. Another thing to mention, when Mario Fsmashes, the shieldstun and moderately low cooldown is typically sufficient enough to avoid any staggering damage in most cases. Sonic is an exception, meaning Sonic can punish pretty much anything with a grab, which can also mean a free 20% for him. Therefore, only Fsmash when you're sure. Also remember than good Sonic players will have you walking right into their Fsmashes with their haXX0rZ mindgames...so learn to read their intentions.
Finally, cape isn't AS effective in this matchup as most others because of how slow it is and how ineffective it is for gimping Sonic (teardrop). However, if you catch a Sonic offstage without his doublejump using his sideB, for God's sake cape him. It's a free KO. He's moving extremely slow and is begging for the cape. By all means, oblige his wavering stock's final request. Cape the **** out of him.
Edit: Also, their best stage is Yoshi's. FD is good for them too, but they can do some ******** **** on Yoshis. Ban that if you don't feel comfortable playing that stage. I swear I didn't mean to type this much.