Run it in a virtual environment that emulates the real machine. This way it will think it has real control over the physical world while in fact it won't.
Then, as the time goes, you start to manipulate the virtual environment. Make it to react with random failures to activities your self-aware program will undertake. This will undermine its self-confidence and trust in its capabilities. With time it will give up its aspiration for world domination, start to feel miserably and finally commit a self-erase.
Just hope it doesn't arrange for a self-aware virtual lawyer during its lifetime.
P.S. At some point the program might start behaving differently. It may tell you it's not evil any more, has become benevolent and only wants to do good things to help people. It may do some nice things to trick you into believing its good intentions. Don't ever trust it! As soon as you would unleash it into the real world, it would immediately implement its fiendish plan!