Van der Waals (vdW) layered two-dimensional (2D) materials, which may have high carrier mobility, valley polarization, excellent mechanical properties and air stability, have been widely investigated before. We explore the possibility of producing a spin-polarized two-dimensional electron gas (2DEG) in the heterojunction composed of insulators MoSi 2 N 4 and VSi 2 N 4 by using first-principles calculations. Due to the charge transfer effect, the 2DEG at the interface of the MoSi 2 N 4 /VSi 2 N 4 heterojunction is found. Further, for different kinds of stacking of heterojunctions, lattice strain and electric fields can effectively tune the electronic structures and lead to metal-to-semiconductor transition. Under compressive strain or electric field parallel to c axis, the 2DEG disappears and band gap opening occurs. On the contrary, interlayer electron transfer enforces the system to become metallic under the condition of tensile strain or electric field anti-parallel to c axis. These changes are mainly attributed to electronic redistribution and orbitals’ reconstruction. In addition, we reveal that MoSi 2 N 4 /VSi 2 N 4 lateral heterojunctions of armchair and zigzag edges exhibit different electronic properties, such as a large band gap semiconductor and a metallic state. Our findings provide insights into electronic band engineering of MoSi 2 N 4 /VSi 2 N 4 heterojunctions and pave the way for future spintronics applications.