It is always possible to flee from an undesired confrontation if the other party is surprised.
It is never possible to flee from an encounter where the opponent party is in striking range. (See Breaking Off From Melee, below.) A party can always flee an encounter if it gains the first initiative.
Whether or not the opponent party will follow in pursuit of the fleeing party depends on the following factors:
What you, the Dungeon Master, have stated in your key concerning the party, if applicable. This is first and foremost in ALL cases.
What the stated characteristics of the creature(s) involved are. That is, if player characters, do they say they will pursue, or if monsters, does their description say that they will always seek to pursue?
Obvious deterrents to pursuit, such as a pool of flaming oil, a secured portal, etc. will modity monster behavior accordingly.
Fleeing party behavior and/or possessions noted by the opponent party will modify pursuit desire.
Relative speed will cause the pursuing party to cease fruitless chase if they are obviously being outdistanced (except if the pursuers are player characters who must state they are halting such chase).
Otherwise 50% of the time (do, 1-3 = pursuit, 4-6 = break off pursuit).
Participants in a melee can opt to attack, parry, fall back, or flee.
Falling back is a retrograde move facing the opponent(s) and can be used in conjunction with a parry, and opponent creatures are able to follow if not otherwise engaged.
Fleeing means as rapid a withdrawal from combat as possible; while it exposes the character to rear attack at the time, subsequent attacks can only be made if the opponent is able to follow the fleeing character at equal or greater speed. [...]
At such time as any creature decides, it can break off the engagement and flee the melee.
To do so, however, allows the opponent a free attack or attack routine. This attack is calculated as if it were a rear attack upon a stunned opponent.
When this attack is completed, the retiring/fleeing party may move away at full movement rate, and unless the opponent pursues and is able to move at a higher rate of speed, the melee is ended and the situation becomes one of encounter avoidance.