-
Notifications
You must be signed in to change notification settings - Fork 46
Add standalone binary for arbitrary Dockerfile support #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7408c07
Add standalone binary for arbitrary Dockerfile support
ghostwriternr 3f71ec3
Move binary to /container-server/sandbox
ghostwriternr 059e2d9
Merge remote-tracking branch 'origin/main' into base-image
ghostwriternr 4cdbdbe
Add --platform flag to docker create commands
ghostwriternr f00c445
Merge remote-tracking branch 'origin/main' into base-image
ghostwriternr 12ba956
Fix signal handling and refactor server lifecycle
ghostwriternr a728cce
Switch base images from Alpine to glibc for binary compat
ghostwriternr 29f3f19
Add E2E tests for standalone binary pattern
ghostwriternr 8a35b58
Document standalone binary pattern and dependencies
ghostwriternr ef9e2ac
Add CMD passthrough docs and release checksums
ghostwriternr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| '@cloudflare/sandbox': patch | ||
| --- | ||
|
|
||
| Add standalone binary support for arbitrary Dockerfiles | ||
|
|
||
| Users can now add sandbox capabilities to any Docker image: | ||
|
|
||
| ```dockerfile | ||
| FROM your-image:tag | ||
|
|
||
| COPY --from=cloudflare/sandbox:VERSION /container-server/sandbox /sandbox | ||
| ENTRYPOINT ["/sandbox"] | ||
|
|
||
| # Optional: run your own startup command | ||
| CMD ["/your-entrypoint.sh"] | ||
| ``` | ||
|
|
||
| The `/sandbox` binary starts the HTTP API server, then executes any CMD as a child process with signal forwarding. | ||
|
|
||
| Includes backwards compatibility for existing custom startup scripts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| ### 🐳 Docker Images Published | ||
|
|
||
| **Default:** | ||
|
|
||
| ```dockerfile | ||
| FROM {{DEFAULT_TAG}} | ||
| ``` | ||
|
|
||
| **With Python:** | ||
|
|
||
| ```dockerfile | ||
| FROM {{PYTHON_TAG}} | ||
| ``` | ||
|
|
||
| **With OpenCode:** | ||
|
|
||
| ```dockerfile | ||
| FROM {{OPENCODE_TAG}} | ||
| ``` | ||
|
|
||
| **Version:** `{{VERSION}}` | ||
|
|
||
| Use the `-python` variant if you need Python code execution, or `-opencode` for the variant with OpenCode AI coding agent pre-installed. | ||
|
|
||
| --- | ||
|
|
||
| ### 📦 Standalone Binary | ||
|
|
||
| **For arbitrary Dockerfiles:** | ||
|
|
||
| ```dockerfile | ||
| COPY --from={{DEFAULT_TAG}} /container-server/sandbox /sandbox | ||
| ENTRYPOINT ["/sandbox"] | ||
| ``` | ||
|
|
||
| **Download via GitHub CLI:** | ||
|
|
||
| ```bash | ||
| gh run download {{RUN_ID}} -n sandbox-binary | ||
| ``` | ||
|
|
||
| **Extract from Docker:** | ||
|
|
||
| ```bash | ||
| docker run --rm {{DEFAULT_TAG}} cat /container-server/sandbox > sandbox && chmod +x sandbox | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Standalone Binary Pattern | ||
|
|
||
| Add Cloudflare Sandbox capabilities to any Docker image by copying the `/sandbox` binary. | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| ```dockerfile | ||
| FROM node:20-slim | ||
|
|
||
| # Required: install 'file' for SDK file operations | ||
| RUN apt-get update && apt-get install -y --no-install-recommends file \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| COPY --from=cloudflare/sandbox:latest /container-server/sandbox /sandbox | ||
|
|
||
| ENTRYPOINT ["/sandbox"] | ||
| CMD ["/your-startup-script.sh"] # Optional: runs after server starts | ||
ghostwriternr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## How CMD Passthrough Works | ||
|
|
||
| The `/sandbox` binary acts as a supervisor: | ||
|
|
||
| 1. Starts HTTP API server on port 3000 | ||
| 2. Spawns your CMD as a child process | ||
| 3. Forwards SIGTERM/SIGINT to the child | ||
| 4. If CMD exits 0, server keeps running; non-zero exits terminate the container | ||
|
|
||
| ## Required Dependencies | ||
|
|
||
| | Dependency | Required For | Install Command | | ||
| | ---------- | ----------------------------------------------- | ---------------------- | | ||
| | `file` | `readFile()`, `writeFile()`, any file operation | `apt-get install file` | | ||
| | `git` | `gitCheckout()`, `listBranches()` | `apt-get install git` | | ||
| | `bash` | Everything (core requirement) | Usually pre-installed | | ||
|
|
||
| Most base images (node:slim, python:slim, ubuntu) include everything except `file` and `git`. | ||
|
|
||
| ## What Works Without Extra Dependencies | ||
|
|
||
| - `exec()` - Run shell commands | ||
| - `startProcess()` - Background processes | ||
| - `exposePort()` - Expose services | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| **"Failed to detect MIME type"** - Install `file` | ||
|
|
||
| **"git: command not found"** - Install `git` (only needed for git operations) | ||
|
|
||
| **Commands hang** - Ensure `bash` exists at `/bin/bash` | ||
|
|
||
| ## Note on Code Interpreter | ||
|
|
||
| `runCode()` requires Python/Node executors not included in the standalone binary. Use the official sandbox images for code interpreter support. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.