\documentclass{article}

\usepackage{tcolorbox}
\usepackage{xsim}    
\usepackage{needspace}

\DeclareExerciseEnvironmentTemplate{custom}
  {%
    \Needspace*{5\baselineskip}
    \begin{tcolorbox}
      \textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}.}%
      \GetExercisePropertyT{subtitle}{ \textit{#1}}%
    \end{tcolorbox}
    \noindent
  }
  {\vspace{\baselineskip}}

\xsimsetup{exercise/template = custom}

\usepackage{lipsum}

\begin{document}

\begin{exercise}[subtitle=Foo bar baz]
  \lipsum[1]
\end{exercise}

\lipsum[2]

\end{document}
