Gravitational instability plays an important role in driving gas accretion in massive protostellar discs. Particularly strong is the global gravitational instability which arises when the disc mass is of order 0.1 of the mass of the central star and has a characteristic spatial scale much greater than the disc s vertical scaleheight. In this paper we use three-dimensional numerical hydrodynamics to study the development of gravitational instabilities in a disc which is embedded in a dense, gaseous envelope. We find that global gravitational instabilities are the dominant mode of angular momentum transport in the disc with infall, in contrast to otherwise identical isolated discs. The accretion torques created by low-order, global modes of the gravitational instability in a disc subject to infall are larger by a factor of several than an isolated disc of the same mass. We show that this global gravitational instability is driven by the strong vertical shear at the interface between the disc and the envelope, and suggest that this process may be an important means of driving accretion on to young stars.