The electron density of two-electron systems, He and H2, was analyzed when prolate spheroids with hard walls confine these systems. For this purpose, Hartree-Fock equations were solved using Roothaan's approach with a basis set defined in prolate spheroidal coordinates imposing Dirichlet boundary conditions. Total energy, its components, and orbital energies were analyzed for several confinements, and some of these results were compared with those reported by other authors to test the performance of the proposed approach. For both systems, the electron density exhibits a maximum value out of the nuclear region for extreme confinements. The chemical bond for H2 was analyzed through the concepts of the quantum theory of atoms in molecules, concluding that the chemical bond of this molecule disappears under extreme conditions. For this system, estimations of the correlation energy indicate that this is a small contribution to the total energy, and the Hartree-Fock method contains the necessary elements to describe the chemical bond for strong confinements.