There's two basic approaches:
you host a scripting language like Lua in your game, and you have your game's "computer" be "programmed" in Lua. Simulating this computer is simply running the user's Lua scripts after setting up a Lua environment that contains the variables and other state you want your computer to represent.
you do the same thing as above, except instead of using Lua you invent your own language or abstraction around a language (such as by placing blocks with certain functionality in the world which interact with blocks nearby them, as in Minecraft).
Really they're basically the same thing, it comes down to how much you want the experience of programming the virtual computer to be like programming a real one or like interacting with your world. And also down to how much effort you want to put into it.
In both cases you need to design what a "computer" in your game looks like. Usually they're quite simple, things that have a small amount of memory and some very basic IO functions. In your game you set aside a block of memory in a variable and you call that your "computer"'s memory. Similarly you write a bunch of functions to manipulate that memory -- to get a value from it, to add a value to it, to print it to the screen, et cetera -- and you hook them up in some fashion to the rest of your gameplay via whatever interface is appropriate for your game design.