Trang này chưa được dịch sang Tiếng Việt: đây là bản tiếng Anh.
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 itA terminal. Press Enter, then ~. to leave it running; glac sandboxes shell web --join <exec id> comes back:
glac sandboxes shell webSleep, 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-upgradeThere 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 sandboxwith 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.