Based on A New Hope, I'm guessing that restraining bolts prevent a droid from straying too far from its owner. How does it achieve that effect, and what would happen if the droid tries to go out of bounds?
Restraining bolts seem to limit the function of a driod and control their actions
A restraining bolt is a small cylindrical device that restricts a droid’s actions when connected to its systems. Droid owners install restraining bolts to limit actions to a set of desired behaviors. Restraining bolts work in conjunction with droid “callers,” small handheld devices that compel a droid to stop what it’s doing and report to its master.
Databank - Restraining Bolts
The restraining bolts seem to give full control to the crew, they also don't seem to be able to "stray too far" as R2 says in the below quote. The above and below also suggest that a droid couldn't go out of bounds, and that it's movements were controlled by the crew.
“There was no use in attempting to run. Restraining bolts restricted them from any movement the crew didn’t desire.”
Droids in Distress - Chapter 7
Droids were also terribly frightened of restraining bolts
“let’s get restraining bolts on these Imperial droids.”
“On it,” Sabine said.
Chopper chortled when he saw what only a droid could recognize—sheer horror in the 3PO unit’s photoreceptors at the mention of restraining bolts.”
Droids in Distress - Chapter 6
I imagine that it somehow overrides droid's OS . When restraining bolt is present, droid simply cannot call certain functions although they exists. In a parallel to real world, it would be similar to getting lite version of application that has some functions locked until you pay and get unlocking code . Some droids are more resistant to such manipulation. For example military or security droids - details here. Manufactures probably intentionally leave backdoor in usual droid's OS for restraining bolts, to control them if something goes wrong. But, when this is undesirable, backdoor could be eliminated.