A Maze of Death

Dick, Philip K. A Maze of Death. New York: Doubleday, 1970.

See for a group of humans in a recursive virtual reality on a spacecraft, and, in the VR world, featuring repeated murders and containing a minor god.

Wikipedia summary of the relevant points:

The group then comes to the conclusion that they are all criminally insane and part of a psychiatric experiment in rehabilitation. Once they admit to having killed the other members they conclude that the experiment must have been a failure. It is at this point that they notice that each of them is tattooed with the phrase, "Persus 9." They decide to ask a tench [= "enormous cube-shaped, gelatinous objects [...] that duplicate items presented to them and give out advice, in anagrams reminiscent of the I Ching] what this means but doing so causes the tench to explode and the world around them to crumble to pieces.

All of them, including the colonists thought to be dead, awake to find that they are actually the crew of the spaceship Persus 9, stranded in orbit around a dead star with no way of calling for help. Their experiences had been a kind of virtual reality, a computer-generated religion that synthesized their beliefs. Their dormancy should save energy of the ship's life support systems for the unlikely case someone would detect the stranded ship and rescue them. It becomes clear that they already completed several cycles of virtual reality dormancy, due to the gradual disintegration each more nightmarish than the previous one. Seth Morley is depressed by this and wonders whether it would be better to let all the air out from the ship and thus kill them all rather than live out the rest of their lives engaging in virtual realities. However, a deity known as the Intercessor, supposedly existing only in the virtual reality program and not a part of the "real" world, appears before Morley and stops him [...]. It offers Morley a choice of possible forms to be reborn as and he decides on "a cactus on some warm world [...]". The Intercessor guides him into the stars, stating he will "live and sleep for a thousand years".

The others, unconcerned with his disappearance, embark on another hallucination which resembles the previous one, only without Seth Morley.

If we do not see Morley really getting out of the ship, we have an image of containment of avatars in a VR, generated in a sense within some sort of "simulation machine," in the phrase of Jorge Martins Rosa (p. 59), inside the mechanical, electronic, and cybernetic environment of a space ship.

RDE, Initial Compiler,26Jan19