Building Mental Endurance Like Physical Strength

I’ve always been curious about this. We train our bodies for stamina, but can we do something similar for our minds? Like, are there actual exercises or habits that help you stay mentally sharp and resilient over long periods, the way cycling builds physical endurance? Would love to hear what works for others.