I had ass surgery last year, the doctors went in through my asshole and removed a tumor (about 5cm long) from my colon about 15cm in from the hole. They used a super cool tool and except for the discomfort of having people dig around in my ass, with multiple people watching, and a sting as they applied the local anesthetic it was perfectly fine. The whole thing took about 1 hour from getting into the hospital, to being back in the car again. The tool they used allowed them to get into the gut, without a full surgery. This tool allowed the doctor to see what she was doing and cut away the tumor with a sort of heat wire cutter. It also had grabbers to pull on the tumor to get it out cleanly. She showed me the tumor when she got it out, proud to show how big of a thing she was able to remove. As the tool used heat to burn the flesh, there was minimal bleeding. I did however bleed from my ass for over two weeks.
The doctor told me to use a bandage on my asshole, to prevent the blood from leaking. Aside from switching out this bandage a couple of times a day, I had to do nothing. It hurt bad for a couple of days and after about a week it was just discomfort. She told me I could poop just as normal and to not force or hold in, just follow the regular schedule and it would be just fine.
As it was explained to me the colon is touching poop all the time and knows how to deal with it. A small burn isn't a big deal for the gut, it won't get infected or be a problem at all. She told me the signs to look for and alert them if any of them showed. Then they could use some medication to deal with things like infections. But luckily it all went fine, pooping didn't hurt more than just existing did and there were no complications.
So for small operations through the asshole, the colon can handle it and it won't get infected. The doctors also use tools to for example burn instead of cut to prevent an fully open wound.