The near-universal genetic code defines the correspondence between codons in genes and amino acids in proteins. We refactored the structure of the genetic code in Escherichia coli and created orthogonal genetic codes that restrict the escape of synthetic genetic information into natural life. We developed orthogonal and mutually orthogonal horizontal gene transfer systems, which permit the transfer of genetic information between organisms that use the same genetic code but restrict the transfer of genetic information between organisms that use different genetic codes. Moreover, we showed that locking refactored codes into synthetic organisms completely blocks invasion by mobile genetic elements, which carry their own translation factors and successfully invade organisms with canonical and compressed genetic codes.