davy-jones-locker 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ .env
2
+ runner.env
3
+ .venv
4
+ __pycache__
5
+ *.pyc
6
+ README.md
@@ -0,0 +1,42 @@
1
+ # The engine's settings. Copy to .env (which isn't committed) and fill in.
2
+ # The runner has its own file (runner.env.example): nothing here reaches it.
3
+
4
+ # Postgres, for saved graphs, stored files and run records, and for SQL nodes
5
+ # that read your own tables. Off until you set DATABASE_URL: those endpoints
6
+ # answer 503, and everything else works. With engine-shared (its .env has
7
+ # these roles and passwords), start it, uncomment the `shared` network lines
8
+ # in compose.yaml, and uncomment the two URLs below. The engine's tables go in
9
+ # schema FLOW_SCHEMA, created the first time the database answers.
10
+ # DATABASE_URL=postgresql://engine:engine-dev@postgres:5432/flow
11
+ FLOW_SCHEMA=flow
12
+
13
+ # The database server-side SQL reads (attached read-only as "db"), through a
14
+ # read-only role (engine-shared/postgres/engine-roles.sql makes one).
15
+ # Empty: DATABASE_URL, whose role can read the engine's own tables too.
16
+ # QUERY_DATABASE_URL=postgresql://engine_reader:engine-reader-dev@postgres:5432/flow
17
+
18
+ # What /health reports as the engine's address (the app shows it). The app's
19
+ # compose.yaml usually sets it to the engine's service name.
20
+ PUBLIC_HOST=engine
21
+
22
+ # Limits for SQL on the server, and for uploads.
23
+ QUERY_TIMEOUT_SECONDS=60
24
+ QUERY_MEMORY_LIMIT=1GB
25
+ MAX_UPLOAD_MB=200
26
+
27
+ # How long the engine waits for the runner (it adds 30s for transfer).
28
+ RUN_TIMEOUT_SECONDS=60
29
+
30
+ # The AI assistant in Manage (SQLQuery, PythonScript, JavaScript nodes), through
31
+ # a LiteLLM proxy. Off unless all three settings below are set. The key stays on
32
+ # the engine: the browser never sees it, and the runner can't read it.
33
+ # LITELLM_BASE_URL is the proxy's address (with /v1 or without); requests go to
34
+ # its /chat/completions. ASSIST_MODEL is a model name the proxy offers
35
+ # (there's no default: GET /models on the proxy, with the key, lists them).
36
+ LITELLM_BASE_URL=
37
+ LITELLM_API_KEY=
38
+ ASSIST_MODEL=
39
+ # Rows of each input sent with a request, as examples of its values (0: none,
40
+ # just column names and types).
41
+ ASSIST_SAMPLE_ROWS=3
42
+ ASSIST_TIMEOUT_SECONDS=90
@@ -0,0 +1,5 @@
1
+ .env
2
+ runner.env
3
+ __pycache__/
4
+ *.pyc
5
+ .venv/
@@ -0,0 +1,23 @@
1
+ # DAVY JONES' LOCKER's engine image: the API, listening on 3000. Built from
2
+ # davy-jones-locker/engine/. An app's engine image is built on this one (FROM),
3
+ # adding its entry point; run as it is, it's the engine with nothing added.
4
+ FROM python:3.12-slim
5
+
6
+ ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
7
+ WORKDIR /srv
8
+
9
+ COPY requirements.txt .
10
+ RUN pip install --no-cache-dir --require-hashes -r requirements.txt
11
+
12
+ RUN useradd --system --uid 10001 --create-home --home-dir /home/engine engine
13
+ USER engine
14
+ # DuckDB's postgres extension, fetched now: at run time DuckDB is locked down
15
+ # and can't install anything.
16
+ RUN python -c "import duckdb; duckdb.sql('INSTALL postgres')"
17
+
18
+ COPY davy_jones_locker ./davy_jones_locker
19
+ # The packages Python scripts can import, which the AI assistant tells the model.
20
+ COPY runner/requirements.in ./runner/requirements.in
21
+
22
+ EXPOSE 3000
23
+ CMD ["uvicorn", "davy_jones_locker.main:app", "--host", "0.0.0.0", "--port", "3000"]
@@ -0,0 +1,201 @@
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 [yyyy] [name of copyright owner]
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.
@@ -0,0 +1,238 @@
1
+ Metadata-Version: 2.5
2
+ Name: davy-jones-locker
3
+ Version: 0.1.0
4
+ Summary: The Python engine that executes flowgraphs: SQL on a locked-down DuckDB, Python in a sandboxed runner, saved graphs, and an AI assistant. Its browser shell is davy-jones-locker on npm, on SEAMONSTER.
5
+ Project-URL: Homepage, https://github.com/lukewilliams/davy-jones-locker/tree/main/davy-jones-locker/engine#readme
6
+ Project-URL: Repository, https://github.com/lukewilliams/davy-jones-locker
7
+ Project-URL: Issues, https://github.com/lukewilliams/davy-jones-locker/issues
8
+ Author: Luke Williams
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: data-pipeline,duckdb,fastapi,flowgraph,sandbox
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: FastAPI
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Database
18
+ Requires-Python: >=3.12
19
+ Requires-Dist: duckdb>=1.5
20
+ Requires-Dist: fastapi>=0.141
21
+ Requires-Dist: httpx>=0.28
22
+ Requires-Dist: psycopg[binary]>=3.3
23
+ Requires-Dist: pyarrow>=25
24
+ Requires-Dist: uvicorn>=0.53
25
+ Description-Content-Type: text/markdown
26
+
27
+ # davy-jones-locker (engine)
28
+
29
+ > **Early release.** This is 0.1: the API may change between minor versions
30
+ > until 1.0, so pin an exact version if you depend on it.
31
+
32
+ DAVY JONES' LOCKER's Python engine, which executes flowgraphs on the server
33
+ (FastAPI, port 3000), and **the runner**, the sandbox it runs Python in. An
34
+ app built on the framework runs everything it can in the browser; the engine
35
+ is the second engine, for:
36
+
37
+ - **PythonScript** nodes, which can't run in a browser.
38
+ - **SQL over the backend database**: a SQL node whose query reads a table its
39
+ wired inputs don't supply runs here, over Postgres (attached read-only as
40
+ `db`) and the inputs the browser sends.
41
+ - **Whole graphs on the server**, for schedulers (n8n, say) to trigger.
42
+
43
+ There's no sign-in yet (identity is the next part): keep the engine off the
44
+ public internet until there is. Until then, anyone who can reach it can use
45
+ its AI assistant, and so its LiteLLM key's budget.
46
+
47
+ ## An app's engine
48
+
49
+ An app builds its engine on this one. Its entry point makes the FastAPI app:
50
+
51
+ ```python
52
+ from davy_jones_locker import create_app
53
+
54
+ app = create_app(title="engine-myapp")
55
+ ```
56
+
57
+ and its image starts from the framework's ([Dockerfile](Dockerfile)), adding
58
+ that entry point:
59
+
60
+ ```dockerfile
61
+ FROM davy-jones-locker-engine
62
+ COPY main.py ./
63
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000"]
64
+ ```
65
+
66
+ The runner is used as it is ([runner/Dockerfile](runner/Dockerfile)), until
67
+ an app adds libraries of its own. [../compose.yaml](../compose.yaml) runs
68
+ both, with the runner's safeguards; copy it into the app and name the
69
+ services for it (`engine-myapp`, `engine-myapp-runner`): browsers reach the
70
+ engine through the app's own origin at `/engines/<service>/`.
71
+
72
+ The package is `davy-jones-locker` (Python 3.12+); `pip install -e .` here
73
+ for development. The images don't install it: they copy the package and
74
+ install the pinned, hashed versions in `requirements.txt` and
75
+ `runner/requirements.txt`.
76
+
77
+ ## Settings
78
+
79
+ [.env.example](.env.example) (the engine) and
80
+ [runner.env.example](runner.env.example) (the runner's limits: never
81
+ credentials, since scripts run beside it). The app's compose file usually
82
+ sets `RUNNER_URL` (the runner's address, default `http://runner:3000`) and
83
+ `PUBLIC_HOST` (what `/health` reports, default `engine`).
84
+
85
+ ## API
86
+
87
+ | | |
88
+ |---|---|
89
+ | `GET /health` | `{ status: 'ok', host, port, assistant }`: the app's connection check (`assistant`: `{ model, sampleRows }`, or null when it isn't set up) |
90
+ | `POST /query` | form data: `sql`, and an `input` file per input (Parquet, its filename the reference name: `sqlnode1_data`, or `dataingest1_data.sheet1` for one table of several). Answers with the result as Parquet |
91
+ | `POST /run/python` | form data: `code`, and `input` files as above. Answers with form data: `result` (JSON) and `table` (Parquet) when the last expression was a table |
92
+ | `POST /execute` | JSON `{ document, targets? }`: runs a graph given in full |
93
+ | `POST /graphs/{id}/execute` | JSON `{ targets? }` (optional): runs a saved graph |
94
+ | `GET /graphs`, `GET /graphs/{id}`, `PUT /graphs/{id}` | saved graphs; `PUT` takes `{ name, document }` and answers `{ id, version }` |
95
+ | `PUT /files/{key}` | stores data a DataIngest node read (Parquet), for server runs |
96
+ | `POST /assist` | JSON `{ kind, request, code, inputs }`: the AI assistant writes a node's code. Answers `{ code, note, model }` (see below) |
97
+
98
+ Errors are JSON `{ error }`, their message meant for the user. `/run/python`'s
99
+ `result` is `{ output, value, variables }` or `{ output, error }`:
100
+
101
+ - `output`: what the script printed.
102
+ - `value`: its last expression's value: `{ kind: 'table', rows }` (the table
103
+ is the `table` part), `{ kind: 'json', type, value }`,
104
+ `{ kind: 'text', type, text }` (anything JSON can't hold), or
105
+ `{ kind: 'none' }`.
106
+ - `variables`: its top-level variables, `[{ name, type, summary }]` (for
107
+ promoting them to outputs of their own, later).
108
+
109
+ A graph run (`/execute`, `/graphs/{id}/execute`, e.g. from n8n) runs `targets`
110
+ (default: every node with Auto Run on) and everything upstream, as the browser
111
+ does, and answers `{ runId, status, failed, results }`: per node `{ status,
112
+ error? | rowCount, output?, value?, export? }`, an export's file as
113
+ `{ filename, contentType, size, base64 }`. Runs are recorded in `runs` when
114
+ there's a database. On the server:
115
+
116
+ | Kind | |
117
+ |---|---|
118
+ | SQLQuery | on the server's DuckDB: its inputs and the query database |
119
+ | PythonScript | in the runner |
120
+ | DataIngest | from its tables stored with `PUT /files/{key}` (the keys in the node's `ingest.tables`) |
121
+ | DataExport | to CSV, TSV, JSON or Parquet, returned in the result |
122
+ | JavaScript | refused: browser only until the engine has safeguards for it |
123
+ | anything else | can't run on the server yet |
124
+
125
+ ## AI assistant
126
+
127
+ The Assistant field in SEAMONSTER's Manage panel (SQLQuery, PythonScript and
128
+ JavaScript nodes) asks `POST /assist` ([assist.py](davy_jones_locker/assist.py)),
129
+ which asks a LiteLLM proxy's `/chat/completions`, OpenAI-style. Set it up in
130
+ `.env`:
131
+
132
+ | | |
133
+ |---|---|
134
+ | `LITELLM_BASE_URL` | the proxy's address (with or without `/v1`) |
135
+ | `LITELLM_API_KEY` | its key: stays on the engine. The browser never sees it, and the runner can't read it |
136
+ | `ASSIST_MODEL` | a model name the proxy offers. No default: the assistant is off until it's set |
137
+ | `ASSIST_SAMPLE_ROWS` | rows of each input sent as examples of its values (default 3; 0 sends column names and types only) |
138
+ | `ASSIST_TIMEOUT_SECONDS` | how long to wait for an answer (default 90) |
139
+
140
+ Off (and hidden in the app) unless all three of the first settings are set.
141
+ What the model is sent: the request; the node's kind and current code; each
142
+ input's reference name, columns (name and type), row count and first
143
+ `ASSIST_SAMPLE_ROWS` rows (values cut to 200 characters), which the browser
144
+ works out by running what's upstream; and for SQL, the query database's
145
+ tables and columns, not their rows. For Python, it's told the packages in
146
+ [runner/requirements.in](runner/requirements.in), so enabling one there tells
147
+ it too. It answers by calling a `write_code` tool (code and a note), or with
148
+ a fenced code block. The code only fills the node's editor: nothing runs
149
+ until the user runs it. Prompts and answers aren't logged, only their size
150
+ and time.
151
+
152
+ A LiteLLM proxy on the Docker host rather than on the network: from inside
153
+ the container, that's `host.docker.internal`, which needs
154
+ `extra_hosts: ["host.docker.internal:host-gateway"]` on the engine's service.
155
+
156
+ ## Database
157
+
158
+ The engine owns its tables, in schema `FLOW_SCHEMA` (`flow`), created the
159
+ first time the database answers ([database.py](davy_jones_locker/database.py)):
160
+ `graphs`, `files` (stored data by key), `runs`. Without `DATABASE_URL`, or
161
+ while the database can't be reached, those endpoints answer 503 and graph runs
162
+ aren't recorded; everything else still works, and the engine starts either
163
+ way.
164
+
165
+ SQL reads the query database (`QUERY_DATABASE_URL`, else `DATABASE_URL`),
166
+ attached read-only as catalog `db`: `db.public.orders`, or just `orders`
167
+ (plain names look in the inputs, then `db.public`). Its role should be
168
+ read-only: engine-shared's reader role is, and
169
+ [its script](../engine-shared/postgres/engine-roles.sql) makes the same roles
170
+ on any Postgres.
171
+
172
+ ## Safeguards
173
+
174
+ User code runs in two places here, and neither is trusted.
175
+
176
+ **SQL** ([sql.py](davy_jones_locker/sql.py)). Each query or graph run gets its
177
+ own in-memory DuckDB. Once the query database is attached, DuckDB is locked
178
+ down: no file access, no new extensions or attachments, settings frozen. That
179
+ doesn't stop `postgres_scan()` connecting to any server by connection string,
180
+ so a query must also be one SELECT that calls none of the functions that open
181
+ connections or run SQL given as text (`postgres_*`, `query`, `query_table`),
182
+ checked with DuckDB's own parser. Queries stop after `QUERY_TIMEOUT_SECONDS`
183
+ and are held to `QUERY_MEMORY_LIMIT`.
184
+
185
+ **Python** ([sandbox/](davy_jones_locker/sandbox/)). The engine never runs
186
+ it: the runner does, in a separate container that holds no credentials (its
187
+ settings file is separate, and nothing secret goes in it) and can reach
188
+ nothing but the engine. The container is read-only, unprivileged,
189
+ capability-free and resource-limited ([../compose.yaml](../compose.yaml)).
190
+ Each script runs in its own process with time, CPU, memory and file limits,
191
+ in a scratch directory deleted afterwards, one at a time per container
192
+ (concurrent runs share a user, so could read each other's files: scale with
193
+ replicas). After each run, every process it started is killed, even ones
194
+ that left its process group, so nothing a script leaves running sees the next
195
+ run; the container's init reaps them, so they can't use up its process limit
196
+ either. Python can't be sandboxed from inside itself, so these limits are the
197
+ safeguard, not anything the script is told. In production, Azure Container
198
+ Apps' dynamic sessions (Hyper-V isolated) could replace the runner behind the
199
+ same API.
200
+
201
+ **Libraries**: scripts get exactly what [runner/requirements.in](runner/requirements.in)
202
+ lists (pandas, numpy, pyarrow), compiled to a pinned, hashed
203
+ `runner/requirements.txt` and installed at image build; nothing installs at
204
+ run time. To enable a library, add it there, recompile (the command is in the
205
+ file), and rebuild. An app adds its own the same way, in a runner image
206
+ built on this one.
207
+
208
+ ## Layout
209
+
210
+ ```
211
+ davy_jones_locker/
212
+ main.py the API, and create_app
213
+ settings.py environment settings (.env.example)
214
+ database.py the engine's tables in Postgres
215
+ sql.py locked-down DuckDB sessions, query checks
216
+ runner.py calls to the runner
217
+ executor.py whole-graph runs
218
+ assist.py the AI assistant (through LiteLLM)
219
+ formdata.py multipart/form-data both ways (the runner uses it too)
220
+ sandbox/
221
+ server.py the runner's API, limits, one process per run
222
+ worker.py runs one script
223
+ runner/ the runner's Dockerfile and libraries
224
+ Dockerfile the engine's image
225
+ ```
226
+
227
+ ## Developing without Docker
228
+
229
+ With Python 3.12 and the packages from both lock files installed, from this
230
+ folder:
231
+
232
+ ```
233
+ RUNNER_URL=http://127.0.0.1:9002 uvicorn davy_jones_locker.main:app --port 9001
234
+ uvicorn davy_jones_locker.sandbox.server:app --port 9002
235
+ ```
236
+
237
+ (On Windows the runner can't set its process limits, and there's no container
238
+ around it: development only.)