Skip to content

Sandbox quickstart

Make a sandbox, run commands in it, copy files, open one of its ports, snapshot and fork it, with the glac command line, the Python SDK or the console.

Mis à jour le

français : cette page n’est pas encore traduite, la voici en anglais.

You need a project’s API key in GLAC_API_KEY, and glac or the Python SDK installed: get started says how.

With the command line

One command in a sandbox that is made for it and deleted after it. The exit code is the command’s:

glac run --image python:3.12 -- python3 -c 'print(6*7)'

A sandbox that stays until you delete it:

glac sandboxes create --name web --image python:3.12      # prints its id
glac sandboxes exec web -- python3 --version              # exits with the command's code
echo '<h1>hello</h1>' > index.html
glac sandboxes cp index.html web:/srv/                    # copy files in, and out
glac sandboxes exec web --detach -- python3 -m http.server 3000 --directory /srv
glac sandboxes url web 3000                               # a link to port 3000: whoever has it can open it

A terminal. Press Enter, then ~. to leave it running; glac sandboxes shell web --join <exec id> comes back:

glac sandboxes shell web

Sleep, snapshot, fork and go back:

glac sandboxes sleep web                                  # sleeps now; the next command wakes it
glac sandboxes snapshots create web --name before-upgrade
copy=$(glac sandboxes fork web)                           # a copy that goes on from this moment
glac sandboxes exec "$copy" -- ls /srv
glac sandboxes restore web before-upgrade                 # back to the snapshot, in place
glac sandboxes rm "$copy" web                             # their snapshots stay
glac sandboxes snapshots rm before-upgrade

There is no wake command: whatever needs the sandbox wakes it. glac sbx is short for glac sandboxes. Every command takes --json and then prints what the API returned; glac help sandboxes lists the commands, and the command line page has all of them.

With the Python SDK

from glac import Glac

glac = Glac()  # GLAC_API_KEY and GLAC_API_URL
print(glac.sandboxes.run("echo hello").stdout)          # one command: made, run, deleted

sbx = glac.sandboxes.create(image="python:3.12", name="web")
res = sbx.run("python3 -c 'print(6*7)'")
print(res.exit_code, res.stdout)                        # 0 42

sbx.files.write("/srv/index.html", "<h1>hello</h1>")
print(sbx.files.read_text("/srv/index.html"))
server = sbx.exec("python3 -m http.server 3000 --directory /srv")   # starts it, does not wait
print(sbx.url(3000))                                    # a link to port 3000

sbx.sleep()                                             # the next call wakes it
snap = sbx.snapshot(name="before-upgrade")
copy = sbx.fork(1)[0]                                   # goes on from this moment
sbx.restore(snap)                                       # back to the snapshot, in place
copy.delete()
sbx.delete()
snap.delete()                                           # a snapshot outlives its sandbox

with glac.sandboxes.create() as sbx: deletes the sandbox when the block ends. A command that exits non-zero is a result, not an exception: read res.exit_code. An error of the API raises GlacError, with status, code, message and request_id. The Python SDK page has the rest.

In the console

Open the [console](https://console.glac.ai/console/), pick the project, and choose Sandboxes under Compute. New sandbox makes one from an image or a template, with a size. A sandbox’s page shows its state and why it is awake, its commands and their output, a box to run a command, and buttons for Terminal, Sleep, Restart and Delete. The terminal stays when you close its panel: Attach goes back to it.

Next

Navigation

Saisissez votre recherche…

↑↓ naviguer↵ sélectionnerEsc fermer