Skip to content

DocsGuides

Files and shell

Each session has its own private directory on the Computer:

  • files/ is the session's working directory. The shell starts there and the agent writes its outputs there. File paths in the API are relative to it.
  • attachments/ holds files you add for the agent. They also appear inside the working directory as attachments/<name>.

Browser downloads are stored beside them, in the same session, for the browser and the agent to use.

Session files last until the Computer stops, including across a restart of the Computer's services. They are not restored after computer.stop or reattachment, so save important files in your own storage before you stop the Computer or destroy the session. Files that should outlive the session belong in the Computer's artifacts.

session.destroy keeps the session's directory on the Computer but out of reach of the API. session.destroy(clean: true) deletes it, with its working files, attachments and downloads.

Read and write files

list_files lists one directory level of the working directory. Each entry has relative_path, name, is_dir, size, mode and modified_at. read_file returns a file's bytes. For a large file, open_file streams the bytes as they arrive, so the whole file never sits in memory.

session.list_files(pattern: "*.csv")      # one directory level; pass path: for a subdirectory
bytes = session.read_file("out/report.csv")

# A large file, streamed in chunks:
File.open("export.zip", "wb") do |out|
  session.open_file("out/export.zip") { |chunk| out.write(chunk) }
end

In Ruby, open_file without a block returns an Enumerator of the chunks.

A turn's files

When a turn ends, its result lists the files the agent produced: turn.result.artifacts in Ruby and Python, turn.Result.Artifacts in Go and turn.result?.artifacts in TypeScript. Each entry names a file by its relative_path in the working directory, with its size, sha256, content_type and modified_at. The list holds the files the agent names in its result. A scratch file it writes without naming it isn't listed.

The entries point at files in the working directory; they aren't copies. Read each file with read_file, or open_file for a large one, when the turn ends: a later turn or shell command can change or delete it.

# turn is a turn that has ended, from session.agent.wait.
turn.result.artifacts.each do |file|
  path = file.fetch("relative_path")  # for example "report.csv" or "out/summary.pdf"
  bytes = session.read_file(path)
  # Save bytes in your application's own file store.
end

Give the agent files

write_file puts a file in attachments/, not in the working directory itself. The agent is told about new attachments when its next turn starts, including the turn your answer to a question starts:

session.write_file("brief.md", File.read("brief.md"))
# The next session.agent.run sees "brief.md" as an attachment.
session.read_file("attachments/brief.md")  # read it back

Use write_file for input documents the agent needs. The name must be a single file name, with no directories. Attachments are stored apart from the files the agent creates in its working directory.

Browser downloads

A download that finishes in a session's browser is kept with that session, for its browser and its agent to use. It isn't one of a turn's files. To get a downloaded file back, ask for it in the goal: the agent copies the file into its working directory and lists it in the turn's result, and you read it like any of the turn's files.

Downloads stay on the Computer only until it stops.

The shell

Shell access is enabled by Pine per project. It lets your application and the Playground run commands and open interactive terminals. Ask Pine to enable it from your project's Capabilities page. Agent tasks and file operations remain available without direct Shell access.

Each session has its own bash shell. It starts in the working directory, with $PINE_SESSION set to the session's name.

Run commands with exec

result = session.exec("make test", timeout_ms: 30_000) do |event|
  puts event.text if event.type == :stdout  # output, standard error included
end
result.stdout                       # everything the command printed
result.exit_code                    # 0 when it succeeded, otherwise its exit status

exec runs one command per call and streams its output back as it runs. exec is meant for short commands, such as running a script or a test suite, or checking a file. Standard error is merged into standard output, so everything arrives as :stdout events and in result.stdout; result.stderr stays empty. A command that succeeds ends with result.exit_code set to 0. A command that exits with another code ends with an :error event whose error["evalue"] holds the code, and result.exit_code is that code as an Integer. result.exit_code is nil only when no exit status arrived: the command timed out or the stream ended early. Every call runs in the session's same shell, so the current directory and exported variables carry over from one command to the next. Pass cwd: to run in another directory; like cd, it carries over too. timeout_ms: (TimeoutMs in Go, timeoutMs in TypeScript, timeout_seconds in Python) stops the command when the time is up, and the result's error (error_message in Ruby, Error in Go, error in TypeScript and Python) says why. It defaults to, and can be at most, 30 minutes.

A missing Shell grant returns 403 (PineSandbox::ForbiddenError); request access from Pine before retrying.

A dropped exec stream can't be resumed: sending the request again runs the command again. exec raises PineSandbox::ConflictError (409) in two cases: a person holds control of the session, or the session's shell was lost. Read session.control_state to tell them apart: if no person holds control, call session.recreate_terminal! and retry.

The stream sends the same 20-second keep-alive as the agent's events (see Agent: keep-alive).

Interactive terminal

The Playground's Shell tab supports interactive programs, editors and REPLs. Both Console and Shell check access before offering command entry. They explain when the project needs access or the Computer needs updating. Integrators should also check that the Computer advertises shell in what computer.capabilities (Ruby), computer.capabilities() (Python), computer.Capabilities(ctx) (Go) or computer.capabilities() (TypeScript) returns. Project feature changes reach the Computer on its next attach; Portal checks the current project setting before admitting a new command or terminal. Disabling access does not terminate commands or terminals already running. An older Computer gets updates only when it starts, so Stop and Start it; Pause and Resume don't update it. Save session files before Stop and Start. To embed a terminal in your application, proxy the Computer's GET /v1/sessions/{name}/pty WebSocket through your backend using the session's Authorization: Bearer credential and the pine-pty.v1 subprotocol. Keep that credential on your server. The API reference defines binary terminal frames, JSON resize/flow-control messages, and close reasons.

The shell runs your programs and installed public libraries in the same session workspace used by Pine's agent. Python, Node, Bash pipelines and public document libraries remain available. Pine's proprietary tools and internals are available through Pine agent tasks and supported APIs, not direct shell imports. Direct desktop/X11 access is unavailable from the shell; use the browser viewer and supported browser actions. Customer and agent HOME and temporary directories are separate; put shared inputs, dependencies and outputs in the workspace. Sessions share the Computer's browser identity and resource budget; use separate Computers for separate tenants.

Outbound SSH and generated keys

The Computer includes the ssh, scp and sftp clients, for connections to public hosts. It doesn't run an SSH server or accept inbound shell connections. SSH from the shell leaves through the Computer's normal internet connection, which can have a different country and IP address from the one the browser uses.

For work by Pine's agent, keep long-lived private keys and certificates in your own secret store. Send them through the run's secrets field, under names you choose. Pine adds no SSH-specific secret name or format; the goal says which credential to use. Send the expected host key or fingerprint too, and don't turn off SSH host verification.

The agent can generate a new identity when you ask it to. That identity works until the Computer stops, but its private key isn't kept by default. Before you install the public key as a lasting way to sign in, keep another verified administrator path, unless you have already arranged secure storage of the private key outside the Computer. A turn's files and other session files are no place to keep a private key.

API reference

The routes are in the Computer API: files (/v1/sessions/{name}/files) under Agent, and /sessions/{name}/exec under Shell and Tabs.

What persists across stop and start, including the browser checkpoint, is in Persistence.

By approval Approved developers get the integration guides, the API reference and the SDKs.