If you have a high enough Illusion skill, you can use the Calm or Fear spells or their higher-level versions to prevent your follower or horse from attacking.
Mods or Console Commands
The mod Better Horses, can set horses to flee at the sight of combat, rather than getting involved and killed. This can be set to all horses except Frost and Shadowmere, or to all horses, including the mentioned two.
The Better Horses mod can also set your horse as 'essential' (i.e. unkillable) or increase your horse's health, preventing or lessening the chances of your horse getting killed. It also has other useful, optional horse-related features.
The mod, Better Stealth AI for Followers, claims to prevent followers from rushing into combat:
This mod improves the stealth AI for followers, so they don't rush
into combat before the enemy has fully detected the player. Followers
will also unequip torches while sneaking.
The mod Better Followers or Ultimate Follower Overhaul will allow you to set your NPC follower as essential, preventing them from getting killed.
Note that Better Followers and Ultimate Follower Overhaul will work for Permanent followers only and Quest followers may not be affected. Most quest followers are already set to be 'essential' though. Just be careful with those not marked as essential (see who is not set to be 'essential' here).
You could also use the
setessential console command to set your horse or follower as unkillable.