We present hydrodynamic simulations of the hot cocoon produced when a relativistic jet passes through the gamma-ray burst (GRB) progenitor star and its environment, and we compute the lightcurve and spectrum of the radiation emitted by the cocoon. The radiation from the cocoon has a nearly thermal spectrum with a peak in the X-ray band, and it lasts for a few minutes in the observer frame; the cocoon radiation starts at roughly the same time as when $gamma$-rays from a burst trigger detectors aboard GRB satellites. The isotropic cocoon luminosity ($sim 10^{47}$ erg s$^{-1}$) is of the same order of magnitude as the X-ray luminosity of a typical long-GRB afterglow during the plateau phase. This radiation should be identifiable in the Swift data because of its nearly thermal spectrum which is distinct from the somewhat brighter power-law component. The detection of this thermal component would provide information regarding the size and density stratification of the GRB progenitor star. Photons from the cocoon are also inverse-Compton (IC) scattered by electrons in the relativistic jet. We present the IC lightcurve and spectrum, by post-processing the results of the numerical simulations. The IC spectrum lies in 10 keV--MeV band for typical GRB parameters. The detection of this IC component would provide an independent measurement of GRB jet Lorentz factor and it would also help to determine the jet magnetisation parameter.