It's also how wasm works, and in some sense -- JavaScript. Somehow, these introduce much less security problems.
I'm not sure Javascript has fewer security problems at all. Sandboxes help a lot, but not all sandboxes are equally strong and Javascript engines routinely get popped.