Dynamic Gutenburg block output echoes in WP Dashboard

Excerpt from “Creating dynamic blocks” in the block editor handbook:

The server-side rendering is a function taking the block and the block
inner content as arguments, and returning the markup (quite
similar to shortcodes)

So despite the “render” as in render_callback, a block render callback should not actually echo anything (and neither call any functions that echo something) and instead, return the output — which will later be automatically echoed by WordPress. Therefore in your render_code_block() function, you need to replace the echo with return, i.e. use return 'test (frontend)';..