means that
someone attempts to retain the favour of opposing sides, often by acting disloyally or concealing conflicting allegiances.
Imagine a case where someone is on good terms with two sides that are at odds with each other.; then “To run with the hare and hunt with the hounds” fits well.