I see https://github.com/ApolloAuto/apollo exists which is an autonomous driving software. But I feel that is over kill.
I was trying to imagine either using a sort of electric fence, like a dog collar, and maybe something more analog to be able to detect the perimeter and just have it know to stop or reverse with a quick servo.