142:7 out of prison. According to the title, the reference is to the cave where David hid (57:title). In later use, the prison could be any situation that holds a person captive, including a literal prison.
The righteous will surround me. David looks forward to a time when God will be with him and he will not be alone.