For me, I think it comes down to isolating myself from unexpected stimuli while trying to focus. Listening to a video game song on loop, relatively loudly to block out external noise, is something that has worked well for me.
However, everybody is different. Do you listen to music / white noise / etc while working? If so, what's your go-to?