Run commands in a sandbox
Last updated Oct 23, 2026
Each of the following guides runs a command in a sandbox with exec(). They differ in how the output reaches the caller and in what ends the command:
| Guide | How the output reaches the caller | The command runs until |
|---|---|---|
| Run Python code | In the response, after the code exits | The code exits |
| Run tests from a Git repository | In the response, after the tests finish | The tests finish |
| Stream command output | As server-sent events, while the command runs | It exits, or a disconnect sends it SIGTERM |
| Run background processes | In files that later requests read | It exits, or a later request stops it |
| Follow a background process | As server-sent events, from those files | It exits, or a later request stops it |
| Run a server in the background | Over the server port, and in a log file | The container stops, or a request stops it |
| Open a terminal in the browser | In an interactive terminal, over a WebSocket | You run exit, or your Worker ends the session |
For every option that exec() accepts, refer to Execute commands in the Containers documentation.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"WebPage","@id":"https://developers.cloudflare.com/sandbox/commands/#page","headline":"Run commands in a sandbox","description":"Run Python code or a test suite, stream command output, keep a process running after the request ends, or open an interactive shell in a Linux sandbox.","url":"https://developers.cloudflare.com/sandbox/commands/","inLanguage":"en","image":"https://developers.cloudflare.com/sandbox/commands/og.png?v=b1896115d4c0161a","dateModified":"2026-10-23","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Stream the output of a background process in a Linux sandbox while it runs, or wait until it prints a line. title: Follow a background process image: https://developers.cloudflare.com/sandbox/commands/follow-a-background-process/og.png?v=3ee2d17d926c182c
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/sandbox/llms.txt
Use this file to discover all available pages before exploring further.
Docs