I'll go one further - Only when I'm assisting a tank and the tank hasn't been careful with his targetting.
If you're assisting a tank and the tank accidentally targets something else in the middle of battle, then you may inadvertently tell your pet to attack something else because its the target of the tank. The tank will usually correct his target but the pet remembers the attack command.
It's bad tanking if it happens really. I usually target by tabbing which will usually stay inside the encounter, but if you target by clicking or if you have more than one encounter on the go, then it's possible to end up targeting something outside the encounter by accident. Tanks really shouldn't do this but if your tank is doing it somehow, then you can modify your behaviour accordingly either by targeting directly, issuing back-off then re-attack orders occasionally mid-battle or simply keeping an eye on the pet and if it runs somewhere you didn't expect issue a back-off.
It's not too difficult to deal with.
The other thing that can cause your pet to hare off is a buff that one class has that fears our pets so they run off. As far as I know though, the pet won't pull aggro when this happens. Can't remember which buff it is off-hand.
X