How to create a tight box around a figure?

I want to create a box around my figure that fits exactly the size of the figure since I want to visually check, how much of the available space my figure uses.

How would I do that?

#box(
  stroke: black,
  figure(...)
)

does not create a tight box…

#block(
  figure(
    box(
      width: 200pt,
      height: 200pt,
      stroke: red
    ),
    caption: lorem(2)
  ),
  stroke: blue
)

Using block here since box is for inline objects. If you wish to apply this accross the document, use #show figure: block.with(stroke: black)

Thank you! Sadly, for me this does not work for me. Upon using it, your example creates a box, but is shifted completely to the left, partially outside of the page.

Oh, sorry I forgot it, wrap it in align(center) should fix this:

#align(center, block(
  figure(
    box(
      width: 200pt,
      height: 200pt,
      stroke: red
    ),
    caption: lorem(2)
  ),
  stroke: blue
))

You may replace the box with the content you like, the box here is just for demonstration.

Sadly, this also doesn’t work for me. The blue box does not show, and the caption is wierdly formatted.

hi @cgahr which version of typst you are using? For my it works on typst 0.12; do you test it in clean file, or in your document?