Skip to main content
Use sandbox.run() to execute a command and collect its output. After installing LithosBox, run this example with lithosbox python:
The result contains stdout, stderr, and exit_code. A nonzero exit code does not raise an exception unless you call .check(). The examples below continue with the same sandbox.

Choose a command format

Pass a string when you want shell features such as pipes and redirects:
Pass a list when arguments contain filenames, user input, or other values that should be treated literally. Each list item is a separate argument:
Use stdin to send input to a command:

Keep shell state

A regular run() starts a new shell. Files persist, but changes to the working directory or environment variables do not carry into the next call. Use a session for commands that share shell state:
Closing a session ends its shell. A session keeps state between commands; it does not increase the time allowed for an individual command.

Start a background job

Use background=True for a server, worker, or command that may take longer than about 110 seconds. It accepts a shell string and returns after the job starts. Redirect output to a file so you can read it later.
Check the result in a later call:
A successful start does not mean the job completed successfully. Check its exit file or application status before using the result. Active background jobs keep the sandbox awake; you do not need a keep-alive loop. background=True does not accept stdin or return a process ID. Write input to a file first. If you need to stop the job individually, have it record its process ID and use that ID in a later command.

Command limits

Synchronous run() and session calls allow about 110 seconds. Each argument can contain at most 131,071 bytes, and stdin can contain up to 4 MiB per call. Each output stream is limited to 16 MiB. Check result.truncated before relying on a large result; use files for binary output or larger results. See Work with files for transfer options. When you have collected your results and no longer need the sandbox: