Reading this BBC News item reminded me of the TNG episode Ship in a Bottle (episode 6x12, first aired: 25 January 1993) where the holodeck character Moriarty is tricked into moving into an off-line table-top computer running a simulation of the holodeck, Enterprise, and universe, thereby neutralizing his threat to the real ship, Starfleet, and the Federation.
Has the "sandboxing" of an adversarial sentient program into an isolated or quarantined computing environment thereby neutralizing its threat outside of the simulation been used in a science fiction work before this?
It would not have to be related to Star Trek.