There is a related story I think in Mahabharata about how a rat and a
cat temporarily make friendship so that the rat can escape from a fox,
and the cat can escape from a hunter. Anyone know the reference for
I think you are referring to the story of a rat named Palita, and Lomaśa, the cat, from the Śānti-parva. The rat enters a temporary alliance with the cat (which is trapped in a hunter's noose) to save itself from a mongoose and an owl. But to protect itself from the cat it doesn't free the cat until after the hunter returns. After it's been freed, the cat wants to prolong the friendship but the rat says their friendship was born out of a reason and it cannot continue as a cat is its worst enemy and only circumstances made them friends.
The story is several pages long so I'm only quoting the concluding part.
Shanti Parva (Apad-dharma Parva) – Chapter 1464 (136)
Having been thus praised by the cat, the rat thought and spoke these
grave and purposeful words to the cat. 'You are virtuous and I have
heard the words of reason you have spoken to me. Though I am pleased,
I do not trust you. By praising me, or by offering me riches, you
won't be able to get me to associate with you. O friend! The wise do
not subjugate themselves to the enemy.
On this, there was a verse sung by Ushanas. Listen to it. "If one has
had an agreement with a more powerful enemy to achieve a common end,
one must act in a controlled way. Once the task has been
accomplished, one should not trust. In every situation, one must
protect one's own life. All one's possessions and offspring exist only
as long as one is alive. In brief, the supreme view of all the texts
about policy is that one should not trust. Therefore, if one desires
the welfare of one's own self, one must completely distrust men.
Those who are weak, but do not trust, are not killed by their
enemies. But if they trust, even the relatively strong are quickly
slain by the weak."
O cat! Thus, I must always protect my own self from someone like you.
You must also protect yourself from the chandala, whose anger has
been generated.' As it was speaking in this way, terror arose in the
cat and it swiftly entered its hole. Palita knew about the true
purport of the sacred texts and was full of intelligence and
capacity. It was wise. Having said all this, it went to another hole.
Palita was wise and intelligent, though weak. Because of this, though
alone, it was able to overcome many other immensely strong enemies.
A learned person must have an alliance with a capable enemy, just as
the rat and the cat resorted to each other and escaped. '"I have
instructed you about the path to be followed in the dharma of
kshatriyas. O lord of the earth! I have recounted it in detail. Listen
to it briefly again. Those two were firm in their enmity towards each
other, but acted with supreme affection. They then turned their minds
towards subjugating each other. However, by resorting to the strength
of its intelligence, the wiser one subjugated the other one. But if
care is not exercised, a wiser person can be subjugated, even by
someone who is not learned. A person who is scared must act as if he
is not scared. Even if he does not trust, he must act as if he trusts.
One must be careful and not be fickle. If one is fickle, one is
There is a time for allying with enemies. There is a time for fighting
with friends. O Yudhishthira! Those who know about the truth have
said that one must always act in this way. O great king! Having
thought about this, having understood the purport of the sacred texts
and having engaged oneself with care, one must act fearfully, before
the cause for fright presents itself. One must determine one's action
as if one is frightened and decide on counters. Intelligence results
from fear, provided that one engages oneself with care. O king! There
is no fear for a person who is frightened of fear that hasn't
materialized. However, a great fear is generated for a person who is
not frightened, but is careless. One must never offer the counsel,
'Do not be scared.' That leads to ignorance. If one knows, one can go
to those who know about a means to get out of the hardship. A person
who is scared must therefore act as if he is not scared. Even if he
does not trust, he must act as if he trusts. Having comprehended the
gravity of the task, he must not indulge in any falsehood. O
Yudhishthira! In this way, I have recounted the history to you. O
son! Having heard in the midst of these well- wishers, act
accordingly. Use your intelligence to first know the difference
between an enemy and a friend, the time for war and peace and means of
escaping from a difficulty. For a common objective, one must have an
alliance with a stronger enemy. One must associate and act in
accordance with the agreement. However, having accomplished the
objective, one must not trust.
(The Mahabharata: Volume 8, Bibek Debroy)
In the K. M. Ganguli translation, you can find the same story here.