The modern way to do is to use javascript, as Sally CJ noted in the comments.
But, you can get the job done by doing it the old with add_meta_box(). When registering a custom metabox you need to set the context argument to side
to make the metabox appear on the block editor sidebar.
See the metabox documentation for more details on how to add, render and save the custom metabox. You can also find plenty of metabox related examples here on WPSE.