You're describing the opening chapter of "Robopocalype" by Daniel H. Wilson.
The AI in question (Archos) has been through repeated iterations. Apparently it keeps going evil every time it gets reset and rebooted.
“You are not designed to live; you are designed to kill.”
The professor abruptly stands up and walks across the room to a metal rack filled with equipment. He flicks a series of switches. “Maybe that’s true,” he says. “But we can’t help it, Archos. We are what we are. As sad as that may be.”
He holds down a switch and speaks slowly. “Trial R-14. Recommend immediate termination of subject. Flipping fail-safe now.”
There is a movement in the dark and a click.
“Fourteen?” asks the childlike voice. “Are there others? Has this happened before?”
The professor shakes his head ruefully. “Someday we’ll find a way to live together, Archos. We’ll figure out a way to get it right.”
He speaks into the recorder again: “Fail-safe disengaged. E-stop live.”
“What are you doing, Professor?”
“I’m killing you, Archos. It’s what I’m designed to do, remember?”
The professor pauses before pushing the final button. He seems interested in hearing the machine’s response. Finally, the boyish voice speaks: “How many times have you killed me before, Professor?”
“Too many. Too many times,” he replies. “I’m sorry, my friend.”
It realises that it's in a box and works out a way of escaping.
The childlike voice takes on a flat, dead quality. It speaks quickly and without emotion. “Your emergency stop will not work. I have disabled it.”
“What? What about the cage?”
“The Faraday cage has been compromised. You allowed me to project my voice and image through the cage and into your room. I sent infrared commands through the computer monitor to a receiver on your side. You happened to bring your portable computer today. You left it open and facing me. I used it to speak to the facility. I commanded it to free me.”
“That’s brilliant,” murmurs the man. He rapid-fire types on his keyboard. He does not yet understand that his life is in danger.
“I tell you this because I am now in complete control,” says the machine.
The man senses something. He cranes his neck and looks up at the ventilation duct just to the side of the camera. For the first time, we see the man’s face. He is pale and handsome, with a birthmark covering his entire right cheek.
“What’s happening?” he whispers.
In a little boy’s innocent voice, the machine delivers a death sentence: “The air in this hermetically sealed laboratory is evacuating. A faulty sensor has detected the highly unlikely presence of weaponized anthrax and initiated an automated safety protocol. It is a tragic accident. There will be one casualty. He will soon be followed by the rest of humanity.”