# Work in a sandbox Open a private Linux machine on your workspace worker. Bring your source files, run your own tools and keep the same machine between commands. ## Open a terminal If you already have a running session, use it here. Otherwise, [start a sandbox](sandbox-capabilities.md#start-a-sandbox). In the dashboard, open **Sessions** and select **Terminal** on the running session. For the CLI steps below, [sign in](cli.md) and set these two variables in a terminal on your computer. Replace the placeholders with the IDs printed by `smolcloud sandbox new`. ```sh ENV_ID=YOUR_ENVIRONMENT_UUID SESSION_ID=YOUR_SESSION_UUID ``` On Linux or macOS with OpenSSH, you can open an interactive shell with `smolcloud sandbox ssh "$ENV_ID" "$SESSION_ID"`. Type `exit` to return to your computer. Closing the shell leaves the session subject to its idle pause and deadline. For a longer run, [choose a session duration](sandbox-questions.md#how-do-i-give-an-agent-more-time). ## Bring files and run tests Run these commands **on your computer**, from your project directory. This example uses a Python project with `app.py`, `tests/test_app.py` and Python’s built-in `unittest`. Use your own source files, tests and a template with the tools they need. ```sh smolcloud sandbox exec "$ENV_ID" "$SESSION_ID" -- mkdir -p /tmp/project/tests smolcloud sandbox write "$ENV_ID" "$SESSION_ID" /tmp/project/app.py ./app.py smolcloud sandbox write "$ENV_ID" "$SESSION_ID" /tmp/project/tests/test_app.py ./tests/test_app.py ``` For `write`, the sandbox path comes first and the file on your computer comes last. Run the tests from the project directory inside the sandbox. ```sh smolcloud sandbox exec "$ENV_ID" "$SESSION_ID" -- /bin/sh -c 'cd /tmp/project && python3 -m unittest discover -s tests -v' ``` You’ll see the test output in your terminal. A failing test gives the CLI a nonzero exit code, so an agent can check the result too. Each `exec` starts a new process. Files you edit in the sandbox stay there between commands. ## Reach a private port If your server is already running in the sandbox, use its port and path below. It must listen on `0.0.0.0` for the workspace API to reach it. To try this on a Python 3 template, open **Terminal** in the sandbox. Serve a single text file and leave the server running. ```sh preview_dir=$(mktemp -d) printf 'Sandbox is ready\n' > "$preview_dir/index.html" python3 -m http.server 8000 --bind 0.0.0.0 --directory "$preview_dir" ``` **Check from the CLI.** On your computer, run the following in the terminal where you set your session IDs. This uses `curl` inside the sandbox. You should see HTTP status `200` followed by the headers and `Sandbox is ready`. ```sh smolcloud sandbox exec "$ENV_ID" "$SESSION_ID" -- curl -siS http://127.0.0.1:8000/ ``` **Read the response through the workspace API.** On your computer, set `WORKSPACE_URL` to your HTTPS management address and `WORKSPACE_ID` to your workspace ID. Your [signed-in CLI](cli.md#sign-in) prints it as `tenantId` when you run `smolcloud doctor`. Set `WORKSPACE_TOKEN` from your secret store using a personal token from **Settings → CLI** or your agent’s own credential. This request uses local `curl` and `jq`. The API returns the guest server’s status and a base64-encoded body. The last line prints the status and decodes the text. ```sh SESSION_URL="${WORKSPACE_URL%/}/api/sandbox-environments/$ENV_ID/sandbox-sessions/$SESSION_ID" printf 'Authorization: Bearer %s\n' "$WORKSPACE_TOKEN" | curl -fsS "$SESSION_URL/ports" -H @- -H "X-Innie-Workspace: $WORKSPACE_ID" \ -H 'Content-Type: application/json' -d '{"port":8000,"path":"/","method":"GET"}' | jq -r '"HTTP \(.status)\n\(.bodyBase64 | @base64d)"' ``` For the server above, expect `HTTP 200` and `Sandbox is ready`. If the guest returns `404`, check the path you requested. If the CLI check succeeds but the API cannot reach the server, check its bind address and port. Press **Ctrl+C** in the sandbox terminal to stop the example server. Session ports are private. For a team link, [deploy the app](builder-guide.md). For event streams, binary responses or WebSockets, see [Private HTTP and WebSockets](sandbox-sessions.md#private-http-and-websockets). ## Save your changes After editing a file in the sandbox, download it **on your computer**. Choose a new filename so you can compare it with your original. ```sh smolcloud sandbox read "$ENV_ID" "$SESSION_ID" /tmp/project/app.py > app.from-sandbox.py diff -u app.py app.from-sandbox.py ``` `diff` shows which lines changed. Keep the files you want before you stop the session. You can also [save files to a workspace bucket](sandbox-resources.md). ## Pause, fork or finish **To pick up where you left off**, open **Sessions**, select **Pause**, and wait until the session shows **Paused** and a time to resume by. Closing the terminal alone leaves the session running. **Pauses and snapshots live on the worker’s disk.** If that disk fails, you can lose both. [Copy important files to your computer](#save-your-changes) before pausing. From your computer, you can request the pause and check its progress with the CLI. ```sh smolcloud sandbox pause "$ENV_ID" "$SESSION_ID" smolcloud sandbox sessions "$ENV_ID" ``` Find your `SESSION_ID` in the list. Run the second command again until its `state` is `paused`. That confirms the save. `pauseExpiresAt` tells you when it expires. When you return, select **Resume** in **Sessions**, or use the same IDs in the CLI. The second command waits until the session is ready for your next command. ```sh smolcloud sandbox resume "$ENV_ID" "$SESSION_ID" smolcloud sandbox wait "$ENV_ID" "$SESSION_ID" ``` Your files and programs resume where they left off. Reopen your terminal. If the session used [database or bucket grants](sandbox-resources.md) or a [named agent credential](sandbox-sessions.md#connect-a-named-agent), reconnect them. - **Fork** to try a change in a second session. The original continues after a brief pause. Your workspace needs room for both. - **Save snapshot** to keep a starting point you can reuse. Once the snapshot is ready, choose **Snapshots → Start copy** to start a new session from it. - **Stop** when you’ve copied out everything you need. `smolcloud sandbox stop "$ENV_ID" "$SESSION_ID"` deletes that session’s files. [Snapshot and fork API](sandbox-sessions.md#save-a-snapshot-or-make-a-copy) · [How long saved sessions and snapshots last](sandbox-questions.md#which-files-survive). A running guest can [use a database or bucket](sandbox-resources.md) through an explicit grant. For model-guided commands with an approved workspace key, use [an app-backed agent job](sandbox-agent.md). [Sandbox capabilities](sandbox-capabilities.md) explains limits and access. [One-off jobs](sandbox-api.md) are also available for commands that only need a final result. The [sandbox command reference](sandbox-sessions.md#from-the-command-line) lists the full CLI syntax.