https://www.google.com/search?q=can+you+trim+a+cactus+plant&oq
I'm no expert when it comes to cactus, but if you copy and paste the link above you can get a lot of information from people who do know how to grow and care for cactus.
Having said that, would you consider pruning the top portion of the cactus - maybe down to the the top edge of the window. I think that pruning off a substantial portion of the plant will help to stabilize it and also encourage the side shoots to develop, which might also help to stabilize the tippiness of the plant. The folks in the link have posted YT videos that give you step by step instructions.
Really, my only contribution is to suggest that if you decide to prune then prune aggressively. I've had much better success when I pruned aggressively than when I tried to baby the plant along. Good luck!