You can harden your Docker configuration (to not expose anything important) and then you can turn it into a sandbox by using the runsc/gvisor (emulated kernel) runtime. The configuration part alone would be sufficient for 99.9% of attacks, as it would require a kernel 0day to escape or exploit the kernel.
But it's best to just run a dev environment in a VM. Keep in mind that sophisticated attacks may seek to compromise the built binary.
But it's best to just run a dev environment in a VM. Keep in mind that sophisticated attacks may seek to compromise the built binary.