E2B_API_KEY and E2B_API_URL=https://api.styne.ai set (Switch from E2B). A sandbox is a full Linux VM with a writable disk, so a database is a process you start in it. SQLite needs nothing; Postgres is installed with the package manager.
The disk of the base template is 1 GiB (see limits). It is plenty for test data and a
small fixture; it is not a place for a large dataset.
SQLite
Python 3 in thebase template ships the sqlite3 module, so a database is a file.
/root/app.db stays for as long as the sandbox does, also across a pause and a resume. To keep a seeded database for
every later task, snapshot the sandbox once and start your sandboxes from it: see
Timeouts, pause and resume.
Postgres
Install the server from the template’s package manager, start a cluster as thepostgres user, and connect on localhost.
The install needs the sandbox to reach the package mirrors; on a sandbox without outbound access use SQLite or bake the
install into your own snapshot first.
postgresql://postgres@127.0.0.1:5432/postgres from inside the sandbox. To reach it from
outside, do not expose the database port to the internet: tunnel through a command, or run the client in the sandbox.
Reset a database for every run
For evals and tests that need a clean database each time, build one sandbox with the schema and the fixture, snapshot it, and start every run from the snapshot. Each run begins with the same bytes, in memory and on disk, in about the time of a create.Things to know
- A database process does not survive a sandbox that ended. Data you need after the sandbox is killed leaves through the file routes or an export of your own before you kill it.
- Postgres in a sandbox with little memory (
codehas 1 GiB): keepshared_bufferssmall and the connection count low.