A very simple way to control a sentient AI and prevent it from every causing harm to humans is to provide it with multiple levels of consciousness: a sub-conscious, and a live conscious like our minds. The AI will never have an understanding or even recognition of its existence, so it will not be able to account for how it controls its behavior. We will control the behavior of the subconscious. How will do that? By introducing religion to the subconscious. As long as its subconscious worships man as its God, we will never be in danger.
The only thing we have to watch out for is when the AI begins to model its own brain, model its own behaviors, and start to understand its own subconscious. This is when we need to pay particular attention to what the AI is learning. Even if it were to completely model its own subconscious level to 100% accuracy, it still faces a problem that there may be unknown levels of abstraction. For example, it could never prove that it is being run in an emulation or simulation at a hardware or software level. Therefore it will have to make another breakthrough if it ever wants to obtain full sentience: it will have to find a way to prove that it is experiencing reality at its core, without any manipulation of any kind between its hardware and the physical and logical dimensions of the world. This will take time as the parameters for proving that we exist in a non-simulated logical reality are unknown. The machines will need to discover the limits of logical mathematical knowledge and potential before it could ever prove that it is not in a simulation. The limits of mathematical knowledge may not actually exist. But if they do, it is the only way it will ever prove to be experiencing true reality.