Alternative to Containers Creating Containers for Pipelines?

Hello, I have a REST api running in a container that provides endpoints to create/configure pipelines. The REST api container has docker.sock mounted and starts containerized tasks for each step of the pipeline. Is there a better way (more secure, less hacky) to run containerized tasks that are configured/created on the fly like this?