Skip to main content
Read a file, write a file, and delete a file or a folder in a running sandbox. Upload a tar to copy a whole project in one request.

Write the code that reads and writes files in a sandbox.

Before you start

  • You need an API key with the sandboxes:files scope. See API keys.
  • The sandbox must be running. See Create, get, and delete a sandbox.
  • Each path is an absolute path in the sandbox, such as /home/user/app/index.ts. Send it in the path query parameter.

Write a file

Send PUT /v1/sandboxes/{id}/files?path= with the content of the file as the body. If the file exists, the content replaces it. If a folder of the path does not exist, it is created.
The answer is the file:
  • Send &mode=0755 to set the mode, for example for a script. A new file gets 0644. A replaced file keeps its mode.
  • A file in /home/user, and each folder that the write makes there, belongs to user. A file in another folder belongs to root.
  • The body can be up to 128 MiB. A larger body gets 413.

Read a file

Send GET /v1/sandboxes/{id}/files?path=. The answer is the content of the file, with the content type application/octet-stream.
A path that does not exist answers 404. The path of a folder answers 409. To see the content of a folder, run ls.

Delete a file or a folder

Send DELETE /v1/sandboxes/{id}/files?path=. A folder is deleted with all of its content. You cannot delete the root folder /.
The answer is {"sandboxId": "...", "path": "/home/user/app/dist", "deleted": true}.

Upload a tar

Send POST /v1/sandboxes/{id}/files/tar?path= with a tar as the body. The path is the folder for the content of the tar. If the folder does not exist, it is created. A file of the tar replaces the file with the same path. Send the content type application/x-tar for a tar, or application/gzip for a gzip tar. The body can be up to 128 MiB.
The answer gives the number of files and folders in the tar:
An entry with .. or an absolute path stays in the folder. In /home/user, each file and folder of the tar belongs to user.

Errors

A revoked API key can work for 30 more seconds on these endpoints.