We need to create nanides: nano-scale machines that can differentiate between microbes and destroy the bad ones. Just don't piss them off with a phaser blast when they get into the ship's computer core.
Look into immunology, it's a biologically mostly solved problem with the mammalian adaptive immune system.
...In the sense we're here because an implementation evolved, however, the physics and minutiae of the problem domain are so numerous that even nature with billions of years of time, and the happy accident of intelligent tool using life haven't been able to make significant inroads on nailing down the problems space in an "ahead of the machine" sense yet.
The Covid pandemic shows that immunology is very much not a "solved problem". Any time someone dies of a disease caused by a virus, bacteria, or even cancer, this shows that immunology is very much unfinished.
...In the sense we're here because an implementation evolved, however, the physics and minutiae of the problem domain are so numerous that even nature with billions of years of time, and the happy accident of intelligent tool using life haven't been able to make significant inroads on nailing down the problems space in an "ahead of the machine" sense yet.