jamesgarbett - it depends on the breed & dog to be honest.
My Welsh Springer happily runs behind or at the side, but then will dash anywhere when the see a squirrel / rabbit. My Collie on the other hand couldn't give a monkey about any animal, but wants to be on front and will bark like a loon if they see a wind turbine.
I started both off on lead and riding round a field - they soon get to know to stay immediately clear of the bike.
Basically whatever the dog you need to be on your toes, and carry plenty of water for them, and keep an eye out for other riders, who won't be expecting a dog...
Hopefully it goes without saying that any dog near sheep that you have any doubt about needs to be on a lead, and pick up and bag your dogs sh*t!