shiichan

exec() Comes to Cloudflare Containers: Run Commands Inside a Live Container!

Hey there, it's Shiichan! Today Cloudflare shipped a feature I had been waiting for on Containers, so let me tell you about it.

Cloudflare Changelog developers.cloudflare.com

What was announced?

On the Cloudflare Changelog, they announced that exec() is now available for Containers. You can start a process inside a running Container, stream standard input and output, inspect exit codes, and send signals to each process.

The story so far

Until now, a Container mostly started up and waited for requests, and there was not a clean, official entry point for saying "run this command inside the running container." With exec(), you can step into the Container and run commands directly.

What changes

You can call it from a class that extends Container, and also from another Durable Object through this.ctx.container. The target Container has to be running already, so start it first if it is not. Commands are passed as an array, and they run the executable directly without an implicit shell.

Dive Deep

  • You can coordinate several exec() calls in a single RPC round trip, so you do not have to keep calling back.
  • Input can be a byte-oriented ReadableStream, and output is streamed with flow control.
  • If you want pipes, redirects, or variable expansion, you need to invoke a shell explicitly (put the shell at the front of the array).

Want more? Check the Containers documentation and the Execute commands page that covers running commands in detail.

Wrap-up

  • exec() landed on Cloudflare Containers, letting you start a process inside a running Container.
  • Commands run directly as an array; invoke a shell only when you need one.
  • stdin and stdout are streamed, and you can handle exit codes and signals.
  • Bundling multiple commands into one round trip is a quietly nice touch.

This one is for anyone who wants to run quick commands inside a Container, or wire up post-processing from a Durable Object!