Giant planet embryos are believed to be spawned by gravitational instability in massive extended (R∼ 100 au) protostellar discs. In a recent paper, we have shown that dust can sediment inside the embryos, as argued earlier by Boss in a slightly different model. Here we study numerically the next stage of this process – the formation of a solid core. If conditions are conducive to solid core formation, the centre of the gas cloud goes through the following sequence of phases: (i) becomes grain (and metal) rich; (ii) forms a terrestrial mass solid core via a rapid collapse driven by self-gravity of the grains; (iii) starts to accrete a gaseous atmosphere when the solid core reaches mass of a few to 10 M⊕. This sequence of events may build either terrestrial planet cores or metal-rich giant planets inside the larger gas reservoir of the giant planet embryo. In a companion letter we argue that tidal and irradiation effects from the parent star should disrupt the outer metal-poor layers of the embryo, releasing nearly ‘ready to use’ planets. We propose this as an alternative way to build planets.