├── .github └── workflows │ └── build.yml ├── LICENSE ├── Makefile ├── README.md ├── codapi.json └── sandboxes ├── ash ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── caddy ├── .curlrc ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── chdb ├── Dockerfile ├── box.json ├── build.sh ├── commands.json ├── query.py └── requirements.txt ├── clickhouse ├── box.json ├── build.sh ├── client │ ├── Dockerfile │ └── query.sh ├── commands.json ├── server │ ├── Dockerfile │ ├── config.xml │ ├── database-create.sh │ ├── database-drop.sh │ ├── init.sql │ └── users.xml └── setup.sh ├── cpp ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── debian ├── Dockerfile ├── box.json └── build.sh ├── dotnet ├── Dockerfile ├── box.json ├── build.sh ├── commands.json └── run.sh ├── duckdb ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── elixir ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── gcc ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── go ├── Dockerfile ├── box.json ├── build.sh ├── commands.json ├── go.mod ├── main.go └── main_test.go ├── java ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── javascript └── commands.json ├── kotlin ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── latex ├── Dockerfile ├── box.json ├── build.sh ├── commands.json └── convert.sh ├── lua ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── mariadb ├── box.json ├── build.sh ├── client │ └── Dockerfile ├── commands.json ├── server │ ├── Dockerfile │ ├── database-create.sh │ ├── database-drop.sh │ └── init.sql └── setup.sh ├── mongodb ├── box.json ├── build.sh ├── client │ ├── Dockerfile │ └── query.sh ├── commands.json ├── server │ └── Dockerfile └── setup.sh ├── mssql ├── box.json ├── build.sh ├── client │ ├── Dockerfile │ └── query.sh ├── commands.json ├── server │ ├── Dockerfile │ ├── database-create.sh │ ├── database-drop.sh │ └── query.sh └── setup.sh ├── mysql ├── box.json ├── build.sh ├── client │ └── Dockerfile ├── commands.json ├── server │ ├── Dockerfile │ ├── database-create.sh │ ├── database-drop.sh │ └── init.sql └── setup.sh ├── net-tools ├── .curlrc ├── Dockerfile ├── box.json ├── build.sh ├── commands.json └── run.sh ├── odin ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── php ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── postgres ├── Dockerfile ├── build.sh ├── commands.json ├── database-create.sql ├── database-drop.sql ├── entrypoint.sh └── setup.sh ├── python ├── Dockerfile ├── box.json ├── build.sh ├── commands.json └── requirements.txt ├── raku ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── redis ├── Dockerfile ├── box.json ├── build.sh ├── commands.json └── query.sh ├── redka ├── Dockerfile ├── box.json ├── build.sh ├── commands.json └── query.sh ├── rlang ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── ruby ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── rust ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── shell ├── Dockerfile ├── box.json ├── build.sh ├── codapi.log ├── commands.json └── nginx.log ├── sqlite ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── typescript ├── Dockerfile ├── box.json ├── build.sh └── commands.json ├── vlang ├── Dockerfile ├── box.json ├── build.sh └── commands.json └── zig ├── Dockerfile ├── box.json ├── build.sh ├── commands.json └── main.zig /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | paths: 7 | - "sandboxes/**" 8 | workflow_dispatch: 9 | 10 | permissions: 11 | contents: write 12 | 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v4 19 | - name: Package sandboxes 20 | run: make sandboxes 21 | - name: Attach packages to the "latest" release 22 | uses: softprops/action-gh-release@v2 23 | with: 24 | name: latest 25 | tag_name: latest 26 | files: build/*.tar.gz 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2025 Anton Zhiyanov 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Helper tasks for Codapi sandboxes. 2 | 3 | # Creates a sandbox package which can be installed using the Codapi CLI. 4 | .PHONY: sandbox 5 | sandbox: 6 | @[ -n "$(name)" ] || (echo "Syntax: make sandbox name=" >&2; exit 1) 7 | @echo "Packing $(name) sandbox" 8 | @mkdir -p build 9 | @rm -f build/$(name).zip 10 | @tar -cvzf build/$(name).tar.gz -C sandboxes $(name) 11 | @echo "✓ build/$(name).tar.gz" 12 | 13 | # Creates packages for all sandboxes. 14 | .PHONY: sandboxes 15 | sandboxes: 16 | make sandbox name=ash 17 | make sandbox name=caddy 18 | make sandbox name=chdb 19 | make sandbox name=clickhouse 20 | make sandbox name=cpp 21 | make sandbox name=debian 22 | make sandbox name=dotnet 23 | make sandbox name=duckdb 24 | make sandbox name=elixir 25 | make sandbox name=gcc 26 | make sandbox name=go 27 | make sandbox name=java 28 | make sandbox name=javascript 29 | make sandbox name=kotlin 30 | make sandbox name=latex 31 | make sandbox name=lua 32 | make sandbox name=mariadb 33 | make sandbox name=mongodb 34 | make sandbox name=mssql 35 | make sandbox name=mysql 36 | make sandbox name=net-tools 37 | make sandbox name=odin 38 | make sandbox name=php 39 | make sandbox name=postgres 40 | make sandbox name=python 41 | make sandbox name=raku 42 | make sandbox name=redis 43 | make sandbox name=redka 44 | make sandbox name=rlang 45 | make sandbox name=ruby 46 | make sandbox name=rust 47 | make sandbox name=shell 48 | make sandbox name=sqlite 49 | make sandbox name=typescript 50 | make sandbox name=vlang 51 | make sandbox name=zig 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sandboxes 2 | 3 | This repository contains sandboxes for [Codapi](https://github.com/nalgeon/codapi), a tool for trying programming languages, databases and other software in an isolated environment. 4 | 5 | To use a particular sandbox: 6 | 7 | 1. [Install Codapi](https://github.com/nalgeon/codapi#installation) 8 | 2. Add a sandbox by its name with `./codapi-cli sandbox add `, e.g: 9 | 10 | ```sh 11 | ./codapi-cli sandbox add lua 12 | ./codapi-cli sandbox add go 13 | ./codapi-cli sandbox add mariadb 14 | ``` 15 | 16 | 3. Restart the Codapi server. 17 | 18 | See the available sandboxes below, or [try them out](https://codapi.org/#sandboxes). 19 | 20 | ## What is a sandbox 21 | 22 | Sandbox = image + box + commands: 23 | 24 | - _Image_ as a Docker image containing specific software, like a compiler or a database engine. 25 | - _Box_ is a configuration for running a container: cpu and memory restrictions, file systems, etc. 26 | - _Commands_ are predefined actions you can run in a container. 27 | 28 | You can use sandboxes from this repository or [create your own](https://github.com/nalgeon/codapi/blob/main/docs/add-sandbox.md). 29 | 30 | ## Programming languages 31 | 32 | | Name | Sandbox | 33 | | ------------ | ---------------------------------- | 34 | | `shell` | [Bash/Zsh](sandboxes/shell) | 35 | | `gcc` | [C](sandboxes/gcc) | 36 | | `dotnet` | [C#](sandboxes/dotnet/) | 37 | | `cpp` | [C++](sandboxes/cpp) | 38 | | `elixir` | [Elixir](sandboxes/elixir) | 39 | | `go` | [Go](sandboxes/go) | 40 | | `java` | [Java](sandboxes/java) | 41 | | `typescript` | [JavaScript](sandboxes/typescript) | 42 | | `kotlin` | [Kotlin](sandboxes/kotlin) | 43 | | `lua` | [Lua](sandboxes/lua) | 44 | | `odin` | [Odin](sandboxes/odin) | 45 | | `php` | [PHP](sandboxes/php) | 46 | | `python` | [Python](sandboxes/python) | 47 | | `rlang` | [R](sandboxes/rlang) | 48 | | `raku` | [Raku](sandboxes/raku) | 49 | | `ruby` | [Ruby](sandboxes/ruby) | 50 | | `rust` | [Rust](sandboxes/rust) | 51 | | `typescript` | [TypeScript](sandboxes/typescript) | 52 | | `vlang` | [V](sandboxes/vlang) | 53 | | `zig` | [Zig](sandboxes/zig) | 54 | 55 | ## Databases 56 | 57 | Client-server databases like MySQL typically use two images: a server and a client: 58 | 59 | - The server container is started when you add a sandbox using `codapi-cli`. 60 | - The client container is created by the Codapi server on each request. 61 | 62 | | Name | Sandbox | 63 | | ------------ | ---------------------------------- | 64 | | `chdb` | [chDB](sandboxes/chdb) | 65 | | `clickhouse` | [ClickHouse](sandboxes/clickhouse) | 66 | | `duckdb` | [DuckDB](sandboxes/duckdb) | 67 | | `mariadb` | [MariaDB](sandboxes/mariadb) | 68 | | `mongodb` | [MongoDB](sandboxes/mongodb) | 69 | | `mssql` | [SQL Server](sandboxes/mssql) | 70 | | `mysql` | [MySQL](sandboxes/mysql) | 71 | | `postgres` | [PostgreSQL](sandboxes/postgres) | 72 | | `redis` | [Redis](sandboxes/redis) | 73 | | `redka` | [Redka](sandboxes/redka) | 74 | | `sqlite` | [SQLite](sandboxes/sqlite) | 75 | 76 | ## Network & tools 77 | 78 | | Name | Sandbox | 79 | | ----------- | ----------------------------------------------------------------------- | 80 | | `caddy` | [Caddy](sandboxes/caddy) | 81 | | `latex` | [LaTeX](sandboxes/latex) by [Patricio Díaz](https://github.com/padiazg) | 82 | | `net-tools` | [Network tools](sandboxes/net-tools) | 83 | 84 | ## Contributing 85 | 86 | Contributions are welcome. For anything other than bugfixes, please first open an issue to discuss what you want to change. 87 | 88 | ## Support 89 | 90 | Codapi is mostly a [one-man](https://antonz.org/) project, not backed by a VC fund or anything. 91 | 92 | If you find Codapi useful, please star it on GitHub and spread the word among your peers. It really helps to move the project forward. 93 | 94 | ★ [Subscribe](https://antonz.org/subscribe/) to stay on top of new features. 95 | -------------------------------------------------------------------------------- /codapi.json: -------------------------------------------------------------------------------- 1 | { 2 | "pool_size": 8, 3 | "verbose": true, 4 | "box": { 5 | "runtime": "runc", 6 | "cpu": 1, 7 | "memory": 64, 8 | "network": "none", 9 | "writable": false, 10 | "volume": "%s:/sandbox:ro", 11 | "cap_drop": ["all"], 12 | "ulimit": ["nofile=96"], 13 | "nproc": 64 14 | }, 15 | "step": { 16 | "user": "sandbox", 17 | "action": "run", 18 | "timeout": 5, 19 | "noutput": 4096 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sandboxes/ash/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN adduser --home /sandbox --disabled-password sandbox 4 | 5 | USER sandbox 6 | WORKDIR /sandbox 7 | -------------------------------------------------------------------------------- /sandboxes/ash/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/ash" 3 | } 4 | -------------------------------------------------------------------------------- /sandboxes/ash/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=ash 6 | title=Ash 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/ash/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.sh", 5 | "steps": [ 6 | { 7 | "box": "ash", 8 | "command": ["sh", "main.sh"] 9 | } 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sandboxes/caddy/.curlrc: -------------------------------------------------------------------------------- 1 | silent 2 | -------------------------------------------------------------------------------- /sandboxes/caddy/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache curl jq 4 | RUN apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community caddy 5 | RUN adduser --home /sandbox --disabled-password sandbox 6 | 7 | USER sandbox 8 | WORKDIR /sandbox/src 9 | 10 | COPY --chown=sandbox .curlrc /sandbox 11 | 12 | ENV XDG_DATA_HOME=/tmp 13 | ENV XDG_CONFIG_HOME=/tmp 14 | -------------------------------------------------------------------------------- /sandboxes/caddy/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/caddy", 3 | "volume": "%s:/sandbox/src:ro", 4 | "tmpfs": ["/tmp:rw,noexec,nosuid,size=16m"] 5 | } 6 | -------------------------------------------------------------------------------- /sandboxes/caddy/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=caddy 6 | title=Caddy 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/caddy/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.sh", 5 | "steps": [ 6 | { 7 | "box": "caddy", 8 | "command": ["sh", "main.sh"] 9 | } 10 | ] 11 | }, 12 | "exec": { 13 | "engine": "docker", 14 | "entry": "main.sh", 15 | "before": { 16 | "box": "caddy", 17 | "action": "run", 18 | "detach": true, 19 | "command": ["caddy", "run"] 20 | }, 21 | "steps": [ 22 | { 23 | "box": ":name", 24 | "action": "exec", 25 | "command": ["sh", "main.sh"], 26 | "noutput": 102400 27 | } 28 | ], 29 | "after": { 30 | "box": ":name", 31 | "action": "stop" 32 | } 33 | }, 34 | "exec-validate": { 35 | "engine": "docker", 36 | "entry": "main.sh", 37 | "before": { 38 | "box": "caddy", 39 | "action": "run", 40 | "command": ["caddy", "validate"] 41 | }, 42 | "steps": [ 43 | { 44 | "box": "caddy", 45 | "action": "run", 46 | "detach": true, 47 | "command": ["caddy", "run"] 48 | }, 49 | { 50 | "box": ":name", 51 | "user": "sandbox", 52 | "action": "exec", 53 | "command": ["sh", "main.sh"], 54 | "noutput": 102400 55 | } 56 | ], 57 | "after": { 58 | "box": ":name", 59 | "action": "stop" 60 | } 61 | }, 62 | "validate": { 63 | "engine": "docker", 64 | "entry": "Caddyfile", 65 | "steps": [ 66 | { 67 | "box": "caddy", 68 | "command": ["caddy", "validate"] 69 | } 70 | ] 71 | }, 72 | "validate-json": { 73 | "engine": "docker", 74 | "entry": "caddy.json", 75 | "steps": [ 76 | { 77 | "box": "caddy", 78 | "command": ["caddy", "validate", "--config", "caddy.json"] 79 | } 80 | ] 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /sandboxes/chdb/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.12-slim 2 | 3 | COPY requirements.txt /tmp 4 | RUN pip install --no-cache-dir -r /tmp/requirements.txt && rm -f /tmp/requirements.txt 5 | COPY *.py /opt 6 | 7 | RUN adduser --home /sandbox --disabled-password sandbox 8 | 9 | USER sandbox 10 | WORKDIR /sandbox 11 | 12 | ENV PYTHONDONTWRITEBYTECODE=1 13 | ENV PYTHONUNBUFFERED=1 14 | -------------------------------------------------------------------------------- /sandboxes/chdb/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/chdb", 3 | "memory": 256, 4 | "tmpfs": ["/tmp:rw,exec,nosuid,size=64m"], 5 | "ulimit": ["nofile=1024"] 6 | } 7 | -------------------------------------------------------------------------------- /sandboxes/chdb/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=chdb 6 | title=chDB 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/chdb/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.sql", 5 | "steps": [ 6 | { 7 | "box": "chdb", 8 | "command": ["python", "/opt/query.py", "main.sql"] 9 | } 10 | ] 11 | }, 12 | "python": { 13 | "engine": "docker", 14 | "entry": "main.py", 15 | "steps": [ 16 | { 17 | "box": "chdb", 18 | "command": ["python", "main.py"] 19 | } 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sandboxes/chdb/query.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from pathlib import Path 3 | from chdb.session import Session 4 | 5 | 6 | def main(path): 7 | queries = read_queries(path) 8 | if not queries: 9 | return 10 | results = run_queries(queries) 11 | if not results: 12 | return 13 | sys.stdout.write("\n".join(results)) 14 | 15 | 16 | def read_queries(path): 17 | src = Path(path).read_text() 18 | queries = src.split(";\n") 19 | queries = [f"{q};" for q in queries if q] 20 | return queries 21 | 22 | 23 | def run_queries(queries): 24 | results = [] 25 | session = Session() 26 | session.query("create database tmp;") 27 | session.query("use tmp;") 28 | for query in queries: 29 | res = session.query(query, "PrettyCompactNoEscapes") 30 | results.append(res) 31 | return [result_to_str(res) for res in results if res] 32 | 33 | 34 | def result_to_str(result): 35 | lines = [] 36 | for line in str(result).splitlines(): 37 | lines.append(line.lstrip(" 0123456789.")) 38 | return "\n".join(lines) 39 | 40 | 41 | main(sys.argv[1]) 42 | -------------------------------------------------------------------------------- /sandboxes/chdb/requirements.txt: -------------------------------------------------------------------------------- 1 | chdb==3.1.2 2 | numpy 3 | pandas 4 | pyarrow 5 | -------------------------------------------------------------------------------- /sandboxes/clickhouse/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "clickhouse-client", 3 | "image": "codapi/clickhouse-client", 4 | "network": "codapi", 5 | "writable": true 6 | } 7 | -------------------------------------------------------------------------------- /sandboxes/clickhouse/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=clickhouse 6 | title=ClickHouse 7 | 8 | echo "Building $title server image..." 9 | docker build --file ./server/Dockerfile --tag codapi/$name:latest ./server 10 | echo "Done" 11 | 12 | echo "Building $title client image..." 13 | docker build --file ./client/Dockerfile --tag codapi/$name-client:latest ./client 14 | echo "Done" 15 | 16 | cat << EOF 17 | $title images: 18 | - codapi/$name:latest 19 | - codapi/$name-client:latest 20 | 21 | Call setup.sh to finish setting up the sandbox. 22 | EOF 23 | -------------------------------------------------------------------------------- /sandboxes/clickhouse/client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM clickhouse:25.3 2 | 3 | COPY *.sh /etc/clickhouse-client 4 | 5 | RUN adduser --home /sandbox --disabled-password sandbox 6 | USER sandbox 7 | WORKDIR /sandbox 8 | 9 | ENTRYPOINT [] 10 | -------------------------------------------------------------------------------- /sandboxes/clickhouse/client/query.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Read the input value from stdin and replace ';\n' with 'Ø' 5 | input=$(cat | sed ':a;N;$!ba;s/;\n/Ø/g' | sed ':a;N;$!ba;s/\n/ /g') 6 | 7 | # Split the value into lines using 'Ø' as the separator 8 | IFS='Ø' read -ra lines <<< "$input" 9 | 10 | # Iterate over the lines and run each one 11 | for line in "${lines[@]}"; do 12 | clickhouse-client --host clickhouse --user=$1 --database=$1 --format PrettyCompactNoEscapes --output_format_pretty_row_numbers=0 --multiquery --query "$line" 13 | done 14 | -------------------------------------------------------------------------------- /sandboxes/clickhouse/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "before": { 5 | "box": "clickhouse", 6 | "action": "exec", 7 | "command": [ 8 | "sh", 9 | "/etc/clickhouse-client/database-create.sh", 10 | ":name" 11 | ] 12 | }, 13 | "steps": [ 14 | { 15 | "box": "clickhouse-client", 16 | "stdin": true, 17 | "command": ["bash", "/etc/clickhouse-client/query.sh", ":name"] 18 | } 19 | ], 20 | "after": { 21 | "box": "clickhouse", 22 | "action": "exec", 23 | "command": [ 24 | "sh", 25 | "/etc/clickhouse-client/database-drop.sh", 26 | ":name" 27 | ] 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sandboxes/clickhouse/server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM clickhouse:25.3 2 | 3 | RUN useradd --create-home --home /sandbox sandbox 4 | COPY config.xml /etc/clickhouse-server/config.d/codapi.xml 5 | COPY users.xml /etc/clickhouse-server/users.d/codapi.xml 6 | COPY *.sh /etc/clickhouse-client 7 | COPY init.sql /docker-entrypoint-initdb.d/ 8 | 9 | USER sandbox 10 | WORKDIR /sandbox 11 | -------------------------------------------------------------------------------- /sandboxes/clickhouse/server/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 1 3 | 1024000000 4 | 10 5 | 6 | -------------------------------------------------------------------------------- /sandboxes/clickhouse/server/database-create.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | clickhouse-client --multiquery < 2 | 3 | 4 | 5 | 6 | 1 7 | 8 | 127.0.0.1 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sandboxes/clickhouse/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=clickhouse 6 | title=ClickHouse 7 | cpus=1 8 | memory=512m 9 | storage_opt="${STORAGE:+--storage-opt=size=$STORAGE}" 10 | network=codapi 11 | 12 | echo "Creating network..." 13 | docker network create --internal $network >/dev/null 2>&1 || true 14 | echo "Done" 15 | 16 | echo "Starting $title server..." 17 | docker run --detach \ 18 | --name=$name \ 19 | --restart=unless-stopped \ 20 | --cpus=$cpus --memory=$memory $storage_opt \ 21 | --network=$network --pids-limit=1024 \ 22 | --cap-drop=mknod --cap-drop=net_bind_service --cap-drop=net_raw \ 23 | --ulimit=nofile=262144:262144 \ 24 | codapi/$name 25 | echo "Done" 26 | 27 | # Wait for the server to start. 28 | while ! docker exec $name clickhouse-client --query 'SELECT 1' >/dev/null 2>&1; do 29 | sleep 1 30 | done 31 | version=$(docker exec $name clickhouse-client --query 'SELECT version()' | tail -n 1) 32 | 33 | cat << EOF 34 | $title server: 35 | - name = $name 36 | - version = $version 37 | - cpus = $cpus 38 | - memory = $memory 39 | - storage = ${STORAGE:-(none)} 40 | - network = $network 41 | EOF 42 | -------------------------------------------------------------------------------- /sandboxes/cpp/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache g++ 4 | RUN adduser --home /sandbox --disabled-password sandbox 5 | 6 | USER sandbox 7 | WORKDIR /sandbox 8 | -------------------------------------------------------------------------------- /sandboxes/cpp/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/cpp", 3 | "tmpfs": ["/tmp:rw,exec,nosuid,size=16m"] 4 | } 5 | -------------------------------------------------------------------------------- /sandboxes/cpp/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=cpp 6 | title=C++ 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/cpp/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.cpp", 5 | "steps": [ 6 | { 7 | "box": "cpp", 8 | "command": [ 9 | "sh", 10 | "-c", 11 | "g++ -Wall -pedantic --std=c++20 main.cpp -o /tmp/main && /tmp/main" 12 | ] 13 | } 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sandboxes/debian/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:12-slim 2 | 3 | RUN apt-get update && \ 4 | apt-get install -y curl && \ 5 | rm -rf /var/lib/apt/lists/* 6 | 7 | RUN adduser --home /sandbox --disabled-password sandbox 8 | 9 | USER sandbox 10 | WORKDIR /sandbox 11 | -------------------------------------------------------------------------------- /sandboxes/debian/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/debian", 3 | "network": "codapi", 4 | "tmpfs": ["/tmp:rw,noexec,nosuid,size=16m"] 5 | } 6 | -------------------------------------------------------------------------------- /sandboxes/debian/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=debian 6 | title=Debian 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/dotnet/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine 2 | 3 | COPY run.sh /usr/share/dotnet 4 | 5 | RUN adduser --home /sandbox --disabled-password sandbox 6 | 7 | USER sandbox 8 | WORKDIR /sandbox 9 | -------------------------------------------------------------------------------- /sandboxes/dotnet/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/dotnet", 3 | "tmpfs": ["/tmp:rw,exec,nosuid,size=16m"] 4 | } 5 | -------------------------------------------------------------------------------- /sandboxes/dotnet/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=dotnet 6 | title=".NET" 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/dotnet/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.cs", 5 | "steps": [ 6 | { 7 | "box": "dotnet", 8 | "command": ["sh", "/usr/share/dotnet/run.sh"], 9 | "timeout": 8 10 | } 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sandboxes/dotnet/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | DOTNET_HOME="/usr/share/dotnet/sdk/$DOTNET_SDK_VERSION" 4 | 5 | dotnet $DOTNET_HOME/Roslyn/bincore/csc.dll -nologo -reference:$DOTNET_HOME/ref/netstandard.dll -out:/tmp/main.exe main.cs 6 | dotnet exec --runtimeconfig $DOTNET_HOME/vstest.console.runtimeconfig.json /tmp/main.exe 7 | -------------------------------------------------------------------------------- /sandboxes/duckdb/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:12-slim 2 | 3 | RUN apt-get update && \ 4 | apt-get install -y curl unzip && \ 5 | rm -rf /var/lib/apt/lists/* 6 | 7 | ARG VERSION=1.2.2 8 | ARG ARCH=amd64 9 | 10 | RUN < /tmp/texmf.cnf 8 | TEXMFCNF='/tmp:' 9 | 10 | echo "\\documentclass[12pt]{article} 11 | \\usepackage{amsmath} 12 | \\usepackage{amssymb} 13 | \\usepackage{amsfonts} 14 | \\usepackage{xcolor} 15 | \\usepackage[utf8]{inputenc} 16 | \\thispagestyle{empty} 17 | \\begin{document} 18 | $(cat in.tex)\ 19 | \\end{document}" > /tmp/out.tex 20 | 21 | # Compile .tex file to .dvi file with timeout. 22 | timeout 3 latex -no-shell-escape -interaction=nonstopmode -halt-on-error -output-directory=/tmp /tmp/out.tex > /tmp/convert.log 2>&1 23 | if [ $? -ne 0 ]; then 24 | cat /tmp/convert.log 25 | exit 1 26 | fi 27 | 28 | # Convert .dvi to .svg file with timeout. 29 | if [ -z ${OUTPUT_SCALE+x} ]; then OUTPUT_SCALE='1.0'; fi 30 | timeout 3 dvisvgm --no-fonts --scale=$OUTPUT_SCALE --exact -v 0 -o /tmp/out.svg /tmp/out.dvi 31 | if [ $? -ne 0 ]; then 32 | exit 1 33 | fi 34 | 35 | cat /tmp/out.svg 36 | -------------------------------------------------------------------------------- /sandboxes/lua/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache lua5.4 4 | RUN ln -s /usr/bin/lua5.4 /usr/bin/lua 5 | RUN adduser --home /sandbox --disabled-password sandbox 6 | 7 | USER sandbox 8 | WORKDIR /sandbox 9 | -------------------------------------------------------------------------------- /sandboxes/lua/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/lua" 3 | } 4 | -------------------------------------------------------------------------------- /sandboxes/lua/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=lua 6 | title=Lua 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/lua/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.lua", 5 | "steps": [ 6 | { 7 | "box": "lua", 8 | "command": ["lua", "main.lua"] 9 | } 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sandboxes/mariadb/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mariadb-client", 3 | "image": "codapi/mariadb-client", 4 | "memory": 128, 5 | "network": "codapi" 6 | } 7 | -------------------------------------------------------------------------------- /sandboxes/mariadb/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=mariadb 6 | title=MariaDB 7 | 8 | echo "Building $title server image..." 9 | docker build --file ./server/Dockerfile --tag codapi/$name:latest ./server 10 | echo "Done" 11 | 12 | echo "Building $title client image..." 13 | docker build --file ./client/Dockerfile --tag codapi/$name-client:latest ./client 14 | echo "Done" 15 | 16 | cat << EOF 17 | $title images: 18 | - codapi/$name:latest 19 | - codapi/$name-client:latest 20 | 21 | Call setup.sh to finish setting up the sandbox. 22 | EOF 23 | -------------------------------------------------------------------------------- /sandboxes/mariadb/client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache mariadb-client 4 | RUN adduser --home /sandbox --disabled-password sandbox 5 | 6 | USER sandbox 7 | WORKDIR /sandbox 8 | -------------------------------------------------------------------------------- /sandboxes/mariadb/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "before": { 5 | "box": "mariadb", 6 | "user": "root", 7 | "action": "exec", 8 | "command": ["sh", "/etc/mysql/database-create.sh", ":name"] 9 | }, 10 | "steps": [ 11 | { 12 | "box": "mariadb-client", 13 | "stdin": true, 14 | "command": [ 15 | "mariadb", 16 | "--host", 17 | "mariadb", 18 | "--user", 19 | ":name", 20 | "--database", 21 | ":name", 22 | "--table", 23 | "--skip-ssl" 24 | ] 25 | } 26 | ], 27 | "after": { 28 | "box": "mariadb", 29 | "user": "root", 30 | "action": "exec", 31 | "command": ["sh", "/etc/mysql/database-drop.sh", ":name"] 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sandboxes/mariadb/server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mariadb:11.7 2 | 3 | COPY *.sh /etc/mysql/ 4 | COPY init.sql /docker-entrypoint-initdb.d/ 5 | 6 | ENV MYSQL_ALLOW_EMPTY_PASSWORD=1 7 | ENV MYSQL_INITDB_SKIP_TZINFO=1 8 | -------------------------------------------------------------------------------- /sandboxes/mariadb/server/database-create.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | mariadb < 'localhost'; 3 | flush privileges; 4 | -------------------------------------------------------------------------------- /sandboxes/mariadb/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=mariadb 6 | title=MariaDB 7 | cpus=1 8 | memory=384m 9 | storage_opt="${STORAGE:+--storage-opt=size=$STORAGE}" 10 | network=codapi 11 | 12 | echo "Creating network..." 13 | docker network create --internal $network >/dev/null 2>&1 || true 14 | echo "Done" 15 | 16 | echo "Starting $title server..." 17 | docker run --detach \ 18 | --name=$name \ 19 | --restart=unless-stopped \ 20 | --cpus=$cpus --memory=$memory $storage_opt \ 21 | --network=$network --pids-limit=64 \ 22 | --cap-drop=mknod --cap-drop=net_bind_service --cap-drop=net_raw \ 23 | --ulimit=nofile=1024 \ 24 | codapi/$name 25 | echo "Done" 26 | 27 | # Wait for the server to start. 28 | while ! docker exec $name mariadb -e 'SELECT 1' >/dev/null 2>&1; do 29 | sleep 1 30 | done 31 | version=$(docker exec $name mariadb -e 'SELECT VERSION()' | tail -n 1) 32 | 33 | cat << EOF 34 | $title server: 35 | - name = $name 36 | - version = $version 37 | - cpus = $cpus 38 | - memory = $memory 39 | - storage = ${STORAGE:-(none)} 40 | - network = $network 41 | EOF 42 | -------------------------------------------------------------------------------- /sandboxes/mongodb/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mongodb-client", 3 | "image": "codapi/mongodb-client", 4 | "memory": 128, 5 | "network": "codapi", 6 | "writable": true, 7 | "volume": "%s:/sandbox" 8 | } 9 | -------------------------------------------------------------------------------- /sandboxes/mongodb/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=mongodb 6 | title=MongoDB 7 | 8 | echo "Building $title server image..." 9 | docker build --file ./server/Dockerfile --tag codapi/$name:latest ./server 10 | echo "Done" 11 | 12 | echo "Building $title client image..." 13 | docker build --file ./client/Dockerfile --tag codapi/$name-client:latest ./client 14 | echo "Done" 15 | 16 | cat << EOF 17 | $title images: 18 | - codapi/$name:latest 19 | - codapi/$name-client:latest 20 | 21 | Call setup.sh to finish setting up the sandbox. 22 | EOF 23 | -------------------------------------------------------------------------------- /sandboxes/mongodb/client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rtsp/mongosh 2 | 3 | COPY query.sh /etc/mongodb/ 4 | 5 | RUN adduser --home /sandbox --disabled-password sandbox 6 | USER sandbox 7 | WORKDIR /sandbox 8 | -------------------------------------------------------------------------------- /sandboxes/mongodb/client/query.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | input=$(cat main.js) 5 | mongosh --quiet --eval "$input" "mongodb://mongodb/$1" 6 | -------------------------------------------------------------------------------- /sandboxes/mongodb/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.js", 5 | "steps": [ 6 | { 7 | "box": "mongodb-client", 8 | "command": ["bash", "/etc/mongodb/query.sh", ":name"], 9 | "timeout": 8 10 | } 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sandboxes/mongodb/server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mongo:8.0 2 | -------------------------------------------------------------------------------- /sandboxes/mongodb/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=mongodb 6 | title=MongoDB 7 | cpus=1 8 | memory=256m 9 | storage_opt="${STORAGE:+--storage-opt=size=$STORAGE}" 10 | network=codapi 11 | 12 | echo "Creating network..." 13 | docker network create --internal $network >/dev/null 2>&1 || true 14 | echo "Done" 15 | 16 | echo "Starting $title server..." 17 | docker run --detach \ 18 | --name=$name \ 19 | --restart=unless-stopped \ 20 | --cpus=$cpus --memory=$memory $storage_opt \ 21 | --network=$network --pids-limit=64 \ 22 | --cap-drop=mknod --cap-drop=net_bind_service --cap-drop=net_raw \ 23 | --ulimit=nofile=1024 \ 24 | codapi/$name 25 | echo "Done" 26 | 27 | # Wait for the server to start. 28 | while ! docker exec $name mongosh --eval 'db.adminCommand("ping")' >/dev/null 2>&1; do 29 | sleep 1 30 | done 31 | version=$(docker exec $name mongosh --eval 'db.version()' | tail -n 1) 32 | 33 | cat << EOF 34 | $title server: 35 | - name = $name 36 | - version = $version 37 | - cpus = $cpus 38 | - memory = $memory 39 | - storage = ${STORAGE:-(none)} 40 | - network = $network 41 | EOF 42 | -------------------------------------------------------------------------------- /sandboxes/mssql/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mssql-client", 3 | "image": "codapi/mssql-client", 4 | "network": "codapi" 5 | } 6 | -------------------------------------------------------------------------------- /sandboxes/mssql/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=mssql 6 | title="SQL Server" 7 | 8 | echo "Building $title server image..." 9 | docker build --file ./server/Dockerfile --tag codapi/$name:latest ./server 10 | echo "Done" 11 | 12 | echo "Building $title client image..." 13 | docker build --file ./client/Dockerfile --tag codapi/$name-client:latest ./client 14 | echo "Done" 15 | 16 | cat << EOF 17 | $title images: 18 | - codapi/$name:latest 19 | - codapi/$name-client:latest 20 | 21 | Call setup.sh to finish setting up the sandbox. 22 | EOF 23 | -------------------------------------------------------------------------------- /sandboxes/mssql/client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache curl gnupg 4 | 5 | RUN </dev/null 2>&1 || true 23 | echo "Done" 24 | 25 | echo "Starting $title server..." 26 | docker run --detach \ 27 | --name=$name \ 28 | --restart=unless-stopped \ 29 | --cpus=$cpus --memory=$memory $storage_opt \ 30 | --network=$network --pids-limit=1024 \ 31 | --cap-drop=mknod --cap-drop=net_raw \ 32 | --ulimit=nofile=1024 \ 33 | --env="MSSQL_SA_PASSWORD=${MSSQL_SA_PASSWORD}" \ 34 | --env="CODAPI_PASSWORD=${CODAPI_PASSWORD}" \ 35 | codapi/$name 36 | echo "Done" 37 | 38 | # Wait for the server to start. 39 | while ! docker exec $name /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "${MSSQL_SA_PASSWORD}" -Q 'SELECT 1' >/dev/null 2>&1; do 40 | sleep 1 41 | done 42 | version=$(docker exec $name /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "${MSSQL_SA_PASSWORD}" -Q 'SELECT @@VERSION' | tail -n 1) 43 | 44 | cat << EOF 45 | $title server: 46 | - name = $name 47 | - version = $version 48 | - cpus = $cpus 49 | - memory = $memory 50 | - storage = ${STORAGE:-(none)} 51 | - network = $network 52 | EOF 53 | -------------------------------------------------------------------------------- /sandboxes/mysql/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mysql-client", 3 | "image": "codapi/mysql-client", 4 | "network": "codapi" 5 | } 6 | -------------------------------------------------------------------------------- /sandboxes/mysql/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=mysql 6 | title=MySQL 7 | 8 | echo "Building $title server image..." 9 | docker build --file ./server/Dockerfile --tag codapi/$name:latest ./server 10 | echo "Done" 11 | 12 | echo "Building $title client image..." 13 | docker build --file ./client/Dockerfile --tag codapi/$name-client:latest ./client 14 | echo "Done" 15 | 16 | cat << EOF 17 | $title images: 18 | - codapi/$name:latest 19 | - codapi/$name-client:latest 20 | 21 | Call setup.sh to finish setting up the sandbox. 22 | EOF 23 | -------------------------------------------------------------------------------- /sandboxes/mysql/client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mysql:9.2 2 | 3 | RUN adduser --home /sandbox sandbox 4 | USER sandbox 5 | WORKDIR /sandbox 6 | 7 | ENTRYPOINT [] 8 | CMD [] 9 | -------------------------------------------------------------------------------- /sandboxes/mysql/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "before": { 5 | "box": "mysql", 6 | "user": "root", 7 | "action": "exec", 8 | "command": ["sh", "/etc/mysql/database-create.sh", ":name"] 9 | }, 10 | "steps": [ 11 | { 12 | "box": "mysql-client", 13 | "stdin": true, 14 | "command": [ 15 | "mysql", 16 | "--host", 17 | "mysql", 18 | "--user", 19 | ":name", 20 | "--database", 21 | ":name", 22 | "--table" 23 | ] 24 | } 25 | ], 26 | "after": { 27 | "box": "mysql", 28 | "user": "root", 29 | "action": "exec", 30 | "command": ["sh", "/etc/mysql/database-drop.sh", ":name"] 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sandboxes/mysql/server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mysql:9.2 2 | 3 | COPY *.sh /etc/mysql/ 4 | COPY init.sql /docker-entrypoint-initdb.d/ 5 | 6 | ENV MYSQL_ALLOW_EMPTY_PASSWORD=1 7 | ENV MYSQL_INITDB_SKIP_TZINFO=1 8 | -------------------------------------------------------------------------------- /sandboxes/mysql/server/database-create.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | mysql < 'localhost'; 3 | flush privileges; 4 | -------------------------------------------------------------------------------- /sandboxes/mysql/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=mysql 6 | title=MySQL 7 | cpus=1 8 | memory=512m 9 | storage_opt="${STORAGE:+--storage-opt=size=$STORAGE}" 10 | network=codapi 11 | 12 | echo "Creating network..." 13 | docker network create --internal $network >/dev/null 2>&1 || true 14 | echo "Done" 15 | 16 | echo "Starting $title server..." 17 | docker run --detach \ 18 | --name=$name \ 19 | --restart=unless-stopped \ 20 | --cpus=$cpus --memory=$memory $storage_opt \ 21 | --network=$network --pids-limit=64 \ 22 | --cap-drop=mknod --cap-drop=net_bind_service --cap-drop=net_raw \ 23 | --ulimit=nofile=1024 \ 24 | codapi/$name 25 | echo "Done" 26 | 27 | # Wait for the server to start. 28 | until docker exec $name mysqladmin ping --silent; do 29 | sleep 1 30 | done 31 | version=$(docker exec $name mysql -e 'SELECT VERSION()' | tail -n 1) 32 | 33 | cat << EOF 34 | $title server: 35 | - name = $name 36 | - version = $version 37 | - cpus = $cpus 38 | - memory = $memory 39 | - storage = ${STORAGE:-(none)} 40 | - network = $network 41 | EOF 42 | -------------------------------------------------------------------------------- /sandboxes/net-tools/.curlrc: -------------------------------------------------------------------------------- 1 | # maximum time (in seconds) before curl exits 2 | # with a timeout error code (28) 3 | max-time 3 4 | silent 5 | show-error 6 | -------------------------------------------------------------------------------- /sandboxes/net-tools/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache curl curlie net-tools 4 | RUN apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing hurl 5 | RUN adduser --home /sandbox --disabled-password sandbox 6 | 7 | USER sandbox 8 | WORKDIR /sandbox 9 | -------------------------------------------------------------------------------- /sandboxes/net-tools/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/net-tools", 3 | "network": "codapi", 4 | "tmpfs": ["/tmp:rw,noexec,nosuid,size=1m"], 5 | "files": ["sandboxes/net-tools/.curlrc", "sandboxes/net-tools/run.sh"] 6 | } 7 | -------------------------------------------------------------------------------- /sandboxes/net-tools/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=net-tools 6 | title="Network Tools" 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/net-tools/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.sh", 5 | "steps": [ 6 | { 7 | "box": "net-tools", 8 | "command": ["sh", "run.sh"] 9 | } 10 | ] 11 | }, 12 | "curl": { 13 | "engine": "docker", 14 | "entry": "main.curl", 15 | "steps": [ 16 | { 17 | "box": "net-tools", 18 | "command": ["sh", "-c", "cat main.curl | tr '\n' ' ' | sh"] 19 | } 20 | ] 21 | }, 22 | "hurl": { 23 | "engine": "docker", 24 | "entry": "main.hurl", 25 | "steps": [ 26 | { 27 | "box": "net-tools", 28 | "command": ["hurl", "main.hurl"] 29 | } 30 | ] 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sandboxes/net-tools/run.sh: -------------------------------------------------------------------------------- 1 | http() { curlie "$@"; } 2 | 3 | . main.sh 4 | -------------------------------------------------------------------------------- /sandboxes/odin/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main clang20 llvm20 4 | RUN apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing odin 5 | RUN ln -sf /usr/bin/clang-20 /usr/bin/clang 6 | RUN adduser --home /sandbox --disabled-password sandbox 7 | 8 | USER sandbox 9 | WORKDIR /sandbox 10 | -------------------------------------------------------------------------------- /sandboxes/odin/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/odin", 3 | "memory": 512, 4 | "tmpfs": ["/tmp:rw,exec,nosuid,size=16m"] 5 | } 6 | -------------------------------------------------------------------------------- /sandboxes/odin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=odin 6 | title=Odin 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/odin/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.odin", 5 | "steps": [ 6 | { 7 | "box": "odin", 8 | "command": [ 9 | "sh", 10 | "-c", 11 | "odin build . -out:/tmp/main && /tmp/main" 12 | ], 13 | "timeout": 8 14 | } 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sandboxes/php/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache php84 4 | RUN ln -s /usr/bin/php84 /usr/bin/php 5 | RUN adduser --home /sandbox --disabled-password sandbox 6 | 7 | USER sandbox 8 | WORKDIR /sandbox 9 | -------------------------------------------------------------------------------- /sandboxes/php/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/php" 3 | } 4 | -------------------------------------------------------------------------------- /sandboxes/php/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=php 6 | title=PHP 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/php/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.php", 5 | "steps": [ 6 | { 7 | "box": "php", 8 | "command": ["php", "main.php"] 9 | } 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sandboxes/postgres/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache postgresql17 4 | RUN adduser --home /sandbox --disabled-password sandbox 5 | 6 | COPY --chown=postgres:postgres database-create.sql database-drop.sql /var/lib/postgresql/ 7 | COPY entrypoint.sh /run 8 | RUN chmod +x /run/entrypoint.sh 9 | 10 | ENV PGDATA=/var/lib/postgresql/data 11 | ENTRYPOINT ["/run/entrypoint.sh"] 12 | STOPSIGNAL SIGINT 13 | 14 | WORKDIR /sandbox 15 | -------------------------------------------------------------------------------- /sandboxes/postgres/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=postgres 6 | title=PostgreSQL 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | 15 | Call setup.sh to finish setting up the sandbox. 16 | EOF 17 | -------------------------------------------------------------------------------- /sandboxes/postgres/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "before": { 5 | "box": "postgres", 6 | "user": "postgres", 7 | "action": "exec", 8 | "command": [ 9 | "psql", 10 | "--quiet", 11 | "-f", 12 | "/var/lib/postgresql/database-create.sql", 13 | "-v", 14 | "user=:name" 15 | ] 16 | }, 17 | "steps": [ 18 | { 19 | "box": "postgres", 20 | "user": "sandbox", 21 | "action": "exec", 22 | "stdin": true, 23 | "command": ["psql", "--quiet", "--user=:name"] 24 | } 25 | ], 26 | "after": { 27 | "box": "postgres", 28 | "user": "postgres", 29 | "action": "exec", 30 | "command": [ 31 | "psql", 32 | "--quiet", 33 | "-f", 34 | "/var/lib/postgresql/database-drop.sql", 35 | "-v", 36 | "user=:name" 37 | ] 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sandboxes/postgres/database-create.sql: -------------------------------------------------------------------------------- 1 | create user :user; 2 | create database :user with encoding = 'utf8' lc_collate='en_us.utf8' lc_ctype='en_us.utf8' template=template0 owner :user; 3 | -------------------------------------------------------------------------------- /sandboxes/postgres/database-drop.sql: -------------------------------------------------------------------------------- 1 | drop database :user; 2 | drop user :user; -------------------------------------------------------------------------------- /sandboxes/postgres/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | function run_as_postgres() { 4 | local cmd="${@}" 5 | su - postgres -c "${cmd}" 6 | } 7 | 8 | function exec_sql() { 9 | local req="${1}" 10 | run_as_postgres "psql -c \"${req};\"" 11 | } 12 | 13 | function init_postgres() { 14 | chown postgres:postgres "${PGDATA}" 15 | chmod 0700 "${PGDATA}" 16 | 17 | run_as_postgres "initdb --wal-segsize=1 -D ${PGDATA}" 18 | 19 | echo "listen_addresses = 'localhost'" > "${PGDATA}/postgresql.conf" 20 | echo "max_connections = 16" >> "${PGDATA}/postgresql.conf" 21 | echo "wal_level = minimal" >> "${PGDATA}/postgresql.conf" 22 | echo "max_wal_senders = 0" >> "${PGDATA}/postgresql.conf" 23 | echo "fsync = off" >> "${PGDATA}/postgresql.conf" 24 | echo "synchronous_commit = off" >> "${PGDATA}/postgresql.conf" 25 | echo "shared_buffers = 128MB" >> "${PGDATA}/postgresql.conf" 26 | echo "min_wal_size = 2MB" >> "${PGDATA}/postgresql.conf" 27 | echo "max_wal_size = 16MB" >> "${PGDATA}/postgresql.conf" 28 | 29 | echo "local all postgres trust" > "${PGDATA}/pg_hba.conf" 30 | echo "local sameuser all trust" >> "${PGDATA}/pg_hba.conf" 31 | } 32 | 33 | function init_db() { 34 | run_as_postgres "pg_ctl start -D ${PGDATA}" 35 | exec_sql "revoke connect on database postgres from public" 36 | exec_sql "revoke connect on database template0 from public" 37 | exec_sql "revoke connect on database template1 from public" 38 | run_as_postgres "pg_ctl stop -D ${PGDATA}" 39 | } 40 | 41 | if [ ! -f "${PGDATA}/PG_VERSION" ]; then 42 | echo "postgres not found, initializing..." 43 | init_postgres 44 | init_db 45 | fi 46 | 47 | echo "postgres is ready" 48 | run_as_postgres "postgres -D ${PGDATA}" 49 | -------------------------------------------------------------------------------- /sandboxes/postgres/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=postgres 6 | title=PostgreSQL 7 | cpus=1 8 | memory=256m 9 | storage_opt="${STORAGE:+--storage-opt=size=$STORAGE}" 10 | network=none 11 | 12 | echo "Starting $title server..." 13 | docker run --detach \ 14 | --name=$name \ 15 | --restart=unless-stopped \ 16 | --cpus=$cpus --memory=$memory $storage_opt \ 17 | --network=$network --pids-limit=64 \ 18 | --cap-drop=mknod --cap-drop=net_bind_service --cap-drop=net_raw \ 19 | --ulimit=nofile=1024 \ 20 | --read-only \ 21 | --tmpfs=/run/postgresql:rw,noexec,nosuid,size=64k \ 22 | --tmpfs=/var/lib/postgresql/data:rw,noexec,nosuid,size=64m \ 23 | codapi/$name 24 | echo "Done" 25 | 26 | # Wait for the server to start. 27 | while ! docker exec $name psql -U postgres -c 'SELECT 1' >/dev/null 2>&1; do 28 | sleep 1 29 | done 30 | version=$(docker exec $name postgres --version | tail -n 1) 31 | 32 | cat << EOF 33 | $title server: 34 | - name = $name 35 | - version = $version 36 | - cpus = $cpus 37 | - memory = $memory 38 | - storage = ${STORAGE:-(none)} 39 | - network = $network 40 | EOF 41 | -------------------------------------------------------------------------------- /sandboxes/python/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.13-slim 2 | 3 | RUN adduser --home /sandbox --disabled-password sandbox 4 | 5 | COPY requirements.txt /tmp 6 | RUN pip install --no-cache-dir -r /tmp/requirements.txt && rm -f /tmp/requirements.txt 7 | 8 | USER sandbox 9 | WORKDIR /sandbox 10 | 11 | ENV PYTHONDONTWRITEBYTECODE=1 12 | ENV PYTHONUNBUFFERED=1 13 | ENV MPLCONFIGDIR=/tmp 14 | -------------------------------------------------------------------------------- /sandboxes/python/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/python", 3 | "memory": 128, 4 | "tmpfs": ["/tmp:rw,noexec,nosuid,size=16m"] 5 | } 6 | -------------------------------------------------------------------------------- /sandboxes/python/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=python 6 | title=Python 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/python/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.py", 5 | "steps": [ 6 | { 7 | "box": "python", 8 | "command": ["python", "main.py"], 9 | "timeout": 8, 10 | "noutput": 524288 11 | } 12 | ] 13 | }, 14 | "test": { 15 | "engine": "docker", 16 | "entry": "test_main.py", 17 | "steps": [ 18 | { 19 | "box": "python", 20 | "command": ["python", "-m", "unittest"], 21 | "noutput": 8192 22 | } 23 | ] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sandboxes/python/requirements.txt: -------------------------------------------------------------------------------- 1 | matplotlib 2 | numpy 3 | pandas 4 | pyarrow 5 | pydantic 6 | pympler 7 | scikit-learn 8 | seaborn 9 | -------------------------------------------------------------------------------- /sandboxes/raku/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community rakudo 4 | RUN adduser --home /sandbox --disabled-password sandbox 5 | 6 | USER sandbox 7 | WORKDIR /sandbox 8 | -------------------------------------------------------------------------------- /sandboxes/raku/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/raku", 3 | "memory": 128 4 | } 5 | -------------------------------------------------------------------------------- /sandboxes/raku/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=raku 6 | title=Raku 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/raku/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.raku", 5 | "steps": [ 6 | { 7 | "box": "raku", 8 | "command": ["raku", "main.raku"] 9 | } 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sandboxes/redis/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community redis 4 | 5 | COPY query.sh /usr/local/bin/query.sh 6 | RUN chmod +x /usr/local/bin/query.sh 7 | 8 | RUN adduser --home /sandbox --disabled-password sandbox 9 | 10 | USER sandbox 11 | WORKDIR /sandbox 12 | -------------------------------------------------------------------------------- /sandboxes/redis/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/redis" 3 | } 4 | -------------------------------------------------------------------------------- /sandboxes/redis/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=redis 6 | title=Redis 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/redis/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "commands.cli", 5 | "steps": [ 6 | { 7 | "box": "redis", 8 | "command": ["query.sh"] 9 | } 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sandboxes/redis/query.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | # Start Redis server in the background. 5 | redis-server --save "" --appendonly no >/dev/null 2>&1 & 6 | REDIS_PID=$! 7 | 8 | # Wait for the server to be ready. 9 | until $(redis-cli PING >/dev/null 2>&1); do 10 | sleep 0.1 11 | done 12 | 13 | # Execute commands from the provided file. 14 | redis-cli < commands.cli 15 | 16 | # Gracefully shut down the server. 17 | redis-cli SHUTDOWN NOSAVE 18 | wait $REDIS_PID 19 | -------------------------------------------------------------------------------- /sandboxes/redka/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nalgeon/redka:0.6.0 2 | 3 | COPY query.sh /usr/local/bin/query.sh 4 | RUN chmod +x /usr/local/bin/query.sh 5 | 6 | RUN adduser --home /sandbox --disabled-password sandbox 7 | 8 | USER sandbox 9 | WORKDIR /sandbox 10 | 11 | ENTRYPOINT [] 12 | -------------------------------------------------------------------------------- /sandboxes/redka/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/redka" 3 | } 4 | -------------------------------------------------------------------------------- /sandboxes/redka/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=redka 6 | title=Redka 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/redka/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "commands.cli", 5 | "steps": [ 6 | { 7 | "box": "redka", 8 | "command": ["query.sh"] 9 | } 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sandboxes/redka/query.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | # Start Redka server in the background. 5 | redka >/dev/null 2>&1 & 6 | REDKA_PID=$! 7 | 8 | # Wait for the server to be ready. 9 | until $(redis-cli PING >/dev/null 2>&1); do 10 | sleep 0.1 11 | done 12 | 13 | # Execute commands from the provided file. 14 | redis-cli < commands.cli 15 | 16 | # Gracefully shut down the server. 17 | kill $REDKA_PID 18 | wait $REDKA_PID 19 | -------------------------------------------------------------------------------- /sandboxes/rlang/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:12-slim 2 | 3 | RUN apt-get update && \ 4 | apt-get install -y r-base r-recommended && \ 5 | rm -rf /var/lib/apt/lists/* 6 | 7 | RUN adduser --home /sandbox --disabled-password sandbox 8 | 9 | USER sandbox 10 | WORKDIR /sandbox 11 | 12 | ENV XDG_CACHE_HOME=/tmp 13 | -------------------------------------------------------------------------------- /sandboxes/rlang/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/rlang", 3 | "memory": 512, 4 | "tmpfs": ["/tmp:rw,noexec,nosuid,size=16m"], 5 | "ulimit": ["nofile=256"] 6 | } 7 | -------------------------------------------------------------------------------- /sandboxes/rlang/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=rlang 6 | title=R 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/rlang/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.r", 5 | "steps": [ 6 | { 7 | "box": "rlang", 8 | "command": ["Rscript", "main.r"], 9 | "timeout": 8, 10 | "noutput": 524288 11 | } 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sandboxes/ruby/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:3.4-alpine 2 | 3 | RUN apk add --no-cache build-base sqlite 4 | RUN gem install sqlite3 5 | RUN adduser --home /sandbox --disabled-password sandbox 6 | 7 | USER sandbox 8 | WORKDIR /sandbox 9 | -------------------------------------------------------------------------------- /sandboxes/ruby/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/ruby" 3 | } 4 | -------------------------------------------------------------------------------- /sandboxes/ruby/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=ruby 6 | title=Ruby 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/ruby/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.rb", 5 | "steps": [ 6 | { 7 | "box": "ruby", 8 | "command": ["ruby", "main.rb"] 9 | } 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sandboxes/rust/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache rust cargo 4 | RUN adduser --home /sandbox --disabled-password sandbox 5 | 6 | USER sandbox 7 | WORKDIR /sandbox 8 | -------------------------------------------------------------------------------- /sandboxes/rust/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/rust", 3 | "tmpfs": ["/tmp:rw,exec,nosuid,size=16m"] 4 | } 5 | -------------------------------------------------------------------------------- /sandboxes/rust/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=rust 6 | title=Rust 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/rust/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.rs", 5 | "steps": [ 6 | { 7 | "box": "rust", 8 | "command": [ 9 | "sh", 10 | "-c", 11 | "rustc -o /tmp/main main.rs && /tmp/main" 12 | ] 13 | } 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sandboxes/shell/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache aha bash coreutils curl git grep ripgrep zsh 4 | RUN adduser --home /sandbox --disabled-password sandbox 5 | 6 | RUN cd /opt && \ 7 | curl -OL https://github.com/rednafi/httpurr/archive/refs/tags/v0.1.2.tar.gz && \ 8 | tar xvzf v0.1.2.tar.gz && \ 9 | mv httpurr-0.1.2 httpurr 10 | 11 | USER sandbox 12 | WORKDIR /sandbox/src 13 | 14 | RUN git config --global user.email "sandbox@example.com" && \ 15 | git config --global user.name "sandbox" && \ 16 | git config --global init.defaultBranch main 17 | 18 | ENV GIT_AUTHOR_DATE="2024-03-14T15:00:00" 19 | ENV GIT_COMMITTER_DATE="2024-03-14T15:00:00" 20 | -------------------------------------------------------------------------------- /sandboxes/shell/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/shell", 3 | "volume": "%s:/sandbox/src:ro", 4 | "tmpfs": ["/tmp:rw,noexec,nosuid,size=16m"] 5 | } 6 | -------------------------------------------------------------------------------- /sandboxes/shell/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=shell 6 | title=Shell 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/shell/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.sh", 5 | "steps": [ 6 | { 7 | "box": "shell", 8 | "command": ["bash", "main.sh"] 9 | } 10 | ] 11 | }, 12 | "aha": { 13 | "engine": "docker", 14 | "entry": "main.sh", 15 | "steps": [ 16 | { 17 | "box": "shell", 18 | "command": [ 19 | "sh", 20 | "-c", 21 | "bash main.sh | aha | rg --multiline '
([\\s\\S]+)
' -r '$1'" 22 | ] 23 | } 24 | ] 25 | }, 26 | "bash": { 27 | "engine": "docker", 28 | "entry": "main.sh", 29 | "steps": [ 30 | { 31 | "box": "shell", 32 | "command": ["bash", "main.sh"] 33 | } 34 | ] 35 | }, 36 | "sh": { 37 | "engine": "docker", 38 | "entry": "main.sh", 39 | "steps": [ 40 | { 41 | "box": "shell", 42 | "command": ["sh", "main.sh"] 43 | } 44 | ] 45 | }, 46 | "zsh": { 47 | "engine": "docker", 48 | "entry": "main.sh", 49 | "steps": [ 50 | { 51 | "box": "shell", 52 | "command": ["zsh", "main.sh"] 53 | } 54 | ] 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sandboxes/sqlite/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main sqlite 4 | RUN ln -s /usr/bin/sqlite3 /opt/sqlite3 5 | RUN adduser --home /sandbox --disabled-password sandbox 6 | 7 | USER sandbox 8 | WORKDIR /sandbox 9 | -------------------------------------------------------------------------------- /sandboxes/sqlite/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/sqlite", 3 | "volume": "%s:/sandbox/src:ro" 4 | } 5 | -------------------------------------------------------------------------------- /sandboxes/sqlite/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=sqlite 6 | title=SQLite 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/sqlite/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.sql", 5 | "steps": [ 6 | { 7 | "box": "sqlite", 8 | "command": ["sh", "-c", "cat src/main.sql | /opt/sqlite3 -box"] 9 | } 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sandboxes/typescript/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21 2 | 3 | RUN apk add --no-cache nodejs npm 4 | RUN npm install -g esbuild 5 | RUN adduser --home /sandbox --disabled-password sandbox 6 | 7 | USER sandbox 8 | WORKDIR /sandbox 9 | -------------------------------------------------------------------------------- /sandboxes/typescript/box.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "codapi/typescript" 3 | } 4 | -------------------------------------------------------------------------------- /sandboxes/typescript/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | cd "$(dirname "$0")" 4 | 5 | name=typescript 6 | title=TypeScript 7 | 8 | echo "Building $title image..." 9 | docker build --file ./Dockerfile --tag codapi/$name:latest . 10 | echo "Done" 11 | 12 | cat << EOF 13 | $title image: codapi/$name:latest 14 | No additional setup is required. 15 | EOF 16 | -------------------------------------------------------------------------------- /sandboxes/typescript/commands.json: -------------------------------------------------------------------------------- 1 | { 2 | "run": { 3 | "engine": "docker", 4 | "entry": "main.ts", 5 | "steps": [ 6 | { 7 | "box": "typescript", 8 | "command": [ 9 | "sh", 10 | "-c", 11 | "esbuild --bundle --platform=node main.ts | node" 12 | ] 13 | } 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sandboxes/vlang/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:12-slim 2 | 3 | RUN apt-get update && \ 4 | apt-get install -y build-essential curl unzip && \ 5 | rm -rf /var/lib/apt/lists/* 6 | 7 | ARG VERSION=0.4.10 8 | ARG ARCH=linux 9 | 10 | RUN <