  The production cross sections of B$^0_\mathrm{s}$ mesons and charge
conjugates are measured in proton-proton (pp) and PbPb collisions via the
exclusive decay channel B$^0_\mathrm{s}$ $\to$ $\mu^+\mu^-$K$^+$K$^-$ at a
centre-of-mass energy of 5.02 TeV per nucleon pair and within the rapidity
range $|y|$ $\lt$ 2.4 using the CMS detector at the LHC. The pp measurement is
performed as a function of transverse momentum (p$_\mathrm{T}$) of the
B$^0_\mathrm{s}$ meson in the range of 7 to 50 GeV/$c$ and is compared to the
predictions of perturbative QCD calculations. The B$^0_\mathrm{s}$ production
yield in PbPb collisions is measured in two p$_\mathrm{T}$ intervals, 7 to 15
and 15 to 50 GeV/$c$, and compared to the yield in pp collisions in the same
kinematic region. The nuclear modification factor ($R_\mathrm{AA}$) is found to
be 1.5 $\pm$ 0.6 (stat) $\pm$ 0.5 (syst) for 7-15 GeV/$c$, and 0.87 $\pm$ 0.30
(stat) $\pm$ 0.17 (syst) for 15-50 GeV/$c$, respectively. Within current
uncertainties, the results are consistent with models of strangeness
enhancement and a suppression as observed for the B$^+$ mesons.
