# Getting code into a sandbox and results out: files, folders and change lists

> Three ways to move code into a Sandscale sandbox, single files, whole folders as a tar archive, and reading files back, plus how to ask which files the agent changed.

Three ways to move code into a Sandscale sandbox, single files, whole folders as a tar archive, and reading files back, plus how to ask which files the agent changed.

November 23, 2026 · 4 min read · The Sandscale team

Starting a sandbox is the easy part. The first real question in any agent integration is how to get the code in, and how to get the result out. Copying a repository one file at a time is slow and fiddly. Copying it all, including `.env` and `node_modules`, is wasteful and sometimes dangerous. And at the end you usually want one thing: which files did the agent change?

Sandscale’s API has a tool for each of those steps. This post walks through them with the TypeScript SDK and curl, using only calls from the [run code guide](https://sandscale.dev/docs/guides/sandboxes-api) and the [Sandboxes API reference](https://sandscale.dev/docs/reference/api/sandboxes).

Setup for the curl examples, as in the guide:

```sh
API=https://api.sandscale.dev/api/v1/sandbox
AUTH="Authorization: Bearer $SANDSCALE_API_KEY"
```

## Option 1: single files

For a handful of files, such as one script the model just wrote or a config file, write them directly. The content travels base64-encoded in REST:

```sh
curl -X PUT "$API/instances/$ID/files" -H "$AUTH" -H "Content-Type: application/json" \
  -d "{\"path\": \"/workspace/hello.py\", \"content\": \"$(printf 'print(\"hi\")' | base64)\"}"
```

The SDK does the encoding for you and accepts a string or bytes:

```ts
import { Sandscale } from '@sandscale/sdk';

const sandscale = new Sandscale(); // reads SANDSCALE_API_KEY
const box = await sandscale.sandboxes.create({ template: 'builtin:python', timeoutSeconds: 1800 });

// modelWrittenCode is the string your model produced
await sandscale.sandboxes.writeFile(box.id, '/workspace/analysis.py', modelWrittenCode, { region: box.region });
```

`writeFile` also takes a `mode` option for file permissions, useful for a script you want to execute directly. Each request carries one file, up to what the server accepts per request; the reference lists `413 file_too_large` for anything bigger.

This is the right tool for an agent’s code interpreter: the model writes code, you write it to a file, you run it.

## Option 2: a whole folder as one archive

For a repository or a project directory, send everything in one request. `POST /instances/{id}/project` takes a gzip tar archive and unpacks it in the sandbox. An optional `dir` query parameter says where.

```sh
tar -czf project.tgz -C ./my-service .

curl -X POST "$API/instances/$ID/project" -H "$AUTH" \
  -H "Content-Type: application/gzip" --data-binary @project.tgz
```

The reference does not name a content type for the body; `application/gzip` describes it accurately.

The answer describes what happened, per the reference’s `ProjectUpload` type: the target `dir`, the number of `files` and `bytes` unpacked, a count of files that were `skipped` by reason, up to 100 `skipped_paths` with the reason for each, and the `run_id` of the unpack command.

That skip list is worth reading. The reference names three reasons a file is left out: it was gitignored, it was a special file, or it was denied by a rule. So files your `.gitignore` excludes, such as build output and dependency folders, can be left out of the upload. If a file your tests need is missing in the sandbox, `skipped_paths` tells you why.

A few practical notes:

- **Build the archive from a clean checkout** in CI, not from a developer’s working directory, so you know exactly what went in.
- **Check what is not gitignored.** If a `.env` or credentials file is tracked or simply not ignored, it goes in with everything else. A sandbox is a place for code you are willing to have read by the code you are running.
- **Handle the error codes.** The reference lists `413 project_too_large`, `400 invalid_project_archive`, `422 project_extract_failed`, `409 instance_paused` (resume first) and `429 project_upload_busy` (an upload is already in progress; wait and retry).

## Option 3: reading results back

When the agent is done, read what you need. `GET /instances/{id}/files?path=...` reads a file, or lists a directory if the path is one:

```sh
curl "$API/instances/$ID/files?path=/workspace" -H "$AUTH"
```

In the SDK, `listFiles` returns entries with `path`, `name`, `isDir` and `size`, and `readFile` returns the bytes:

```ts
const entries = await sandscale.sandboxes.listFiles(box.id, '/workspace/out', { region: box.region });

for (const entry of entries.filter((e) => !e.isDir)) {
  const bytes = await sandscale.sandboxes.readFile(box.id, entry.path, { region: box.region });
  // save bytes, attach them to the PR, or pass a summary to the model
}
```

## Which files changed?

For a coding agent the most useful question is not “what is in the sandbox” but “what did the agent change”. If you uploaded with the project endpoint, `GET /instances/{id}/project/changes` answers it directly: the files that changed since the project was uploaded.

```sh
curl "$API/instances/$ID/project/changes" -H "$AUTH"
```

Per the reference’s `ProjectChanges` type, the answer has the `dir`, a `changed` list of paths, a `truncated` flag if the list was cut short, and a `run_id`. Read only those files back, and you have the agent’s work without copying the whole tree out.

A pattern for an agent that edits a repository:

1. Upload the repository with the project endpoint.
2. Let the agent work: run tests, edit files, run tests again.
3. Ask for the change list.
4. Read back only the changed files, or run `git diff` in the sandbox and read its output.
5. Turn the result into a branch or a PR on your side, where your normal review rules apply.
6. Stop the sandbox.

Step 5 deliberately happens outside the sandbox. The sandbox never needs your Git push credentials, because it never pushes. It produces a diff; your trusted code decides what to do with it.

## Keep the direction of trust clear

All three options move data across the boundary between your systems and the code you are containing, so it is worth being deliberate about direction:

- **In:** only what the task needs. A clean checkout, minus secrets. Secrets the run genuinely needs go through [Vault](https://sandscale.dev/docs/guides/vault-secrets) as environment variables, scoped to the run, not as files in the archive.
- **Out:** treat everything you read back as untrusted. It was written by code you did not review. Do not execute it on your side, and validate files before acting on them, the same as any input from outside.

## Where to go next

- The [run code guide](https://sandscale.dev/docs/guides/sandboxes-api) has every step with curl and the SDK.
- For running a contributor’s or an agent’s pull request in a throwaway sandbox, see [running untrusted pull request code](https://sandscale.dev/blog/running-untrusted-pr-code-in-sandboxes).
- For long-running commands after the upload, see [streaming sandbox output](https://sandscale.dev/blog/streaming-sandbox-output-typescript).

**On this page**

1. Option 1: single files
2. Option 2: a whole folder as one archive
3. Option 3: reading results back
4. Which files changed?
5. Keep the direction of trust clear
6. Where to go next

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [November 23, 2026 · **A checklist for reviewing a pull request an AI agent wrote** · Agent-written PRs fail in different places than human ones. A practical review checklist: what to read first, the lines that deserve the most suspicion, and what to run before you approve.](https://sandscale.dev/blog/reviewing-an-agent-diff-checklist)
- [November 23, 2026 · **A threat model for AI coding agents: what can go wrong, and where to put the controls** · A practical threat model for coding agents: the assets at risk, the ways untrusted text gets in, the attacker goals, and which control belongs at which layer.](https://sandscale.dev/blog/threat-model-for-ai-coding-agents)

---
Source: https://sandscale.dev/blog/uploading-a-project-into-a-sandbox
