Outer-membrane porins are currently being used to prepare bioinspired nanomembranes for selective ion transport by immobilizing them into polymeric matrices. However, the fabrication of these protein-integrated devices has been found to be strongly influenced by the instability of the β-barrel porin structure, which depends on surrounding environment. In this work, molecular dynamics simulations have been used to investigate the structural stability of a representative porin, OmpF, in three different environments: (i) aqueous solution at pH = 7; (ii) a solution of neutral detergent in a concentration similar to the critical micelle concentration; and (iii) the protein embedded into a neutral detergent bilayer. The results indicate that the surrounding environment not only alters the stability of the β-barrel but affects the internal loop responsible of the ions transport, as well as the tendency of the porin proteins to aggregate into trimers. The detergent bilayer preserves the structure of OmpF protein as is found bacteria membranes, while pure aqueous solution induces a strong destabilization of the protein. An intermediate situation occurs for detergent solution. Our results have been rationalized in terms of protein ⋯ water and protein ⋯ detergent interactions, which makes them extremely useful for the future design of new generation of bioinspired protein-integrated devices.