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 asattachments/<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
files, err := session.ListFiles(ctx, pine.ListFilesOptions{Pattern: "*.csv"}) // one directory level; set Path for a subdirectory
if err != nil {
return err
}
data, err := session.ReadFile(ctx, "out/report.csv")
if err != nil {
return err
}
// A large file, streamed. Close the reader when you're done.
body, err := session.OpenFile(ctx, "out/export.zip")
if err != nil {
return err
}
defer body.Close()
out, err := os.Create("export.zip")
if err != nil {
return err
}
defer out.Close()
if _, err := io.Copy(out, body); err != nil {
return err
}
import { createWriteStream } from "node:fs";
import { Writable } from "node:stream";
await session.listFiles({ pattern: "*.csv" }); // one directory level; pass path for a subdirectory
const bytes = await session.readFile("out/report.csv");
// A large file, streamed as a ReadableStream<Uint8Array>:
const body = await session.openFile("out/export.zip");
await body.pipeTo(Writable.toWeb(createWriteStream("export.zip")));
session.list_files(pattern="*.csv") # one directory level; pass path= for a subdirectory
data = session.read_file("out/report.csv")
# A large file, streamed. The with block closes the stream.
with session.open_file("out/export.zip") as body, open("export.zip", "wb") as out:
for chunk in body:
out.write(chunk)
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
// turn is a turn that has ended, from session.Agent().Wait.
for _, file := range turn.Result.Artifacts {
// For example "report.csv" or "out/summary.pdf".
data, err := session.ReadFile(ctx, file.RelativePath)
if err != nil {
return err
}
// Save data in your application's own file store.
if err := saveOutput(file.RelativePath, data); err != nil {
return err
}
}
// turn is a turn that has ended, from session.agent.wait.
for (const file of turn.result?.artifacts ?? []) {
// For example "report.csv" or "out/summary.pdf".
const bytes = await session.readFile(file.relativePath);
// Save bytes in your application's own file store.
}
# turn is a turn that has ended, from session.agent.wait.
if turn.result:
for file in turn.result.artifacts:
# For example "report.csv" or "out/summary.pdf".
data = session.read_file(file.relative_path)
# Save data in your application's own file store.
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
brief, err := os.ReadFile("brief.md")
if err != nil {
return err
}
if _, err := session.WriteFile(ctx, "brief.md", brief); err != nil {
return err
}
// The next session.Agent().Run sees "brief.md" as an attachment.
back, err := session.ReadFile(ctx, "attachments/brief.md") // read it back
import { readFile } from "node:fs/promises";
await session.writeFile("brief.md", await readFile("brief.md"));
// The next session.agent.run sees "brief.md" as an attachment.
await session.readFile("attachments/brief.md"); // read it back
from pathlib import Path
session.write_file("brief.md", Path("brief.md").read_bytes())
# 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
timeout := 30_000
result, err := session.Exec(ctx, "make test", pine.ExecOptions{TimeoutMs: &timeout}, func(event map[string]any) error {
if event["type"] == "stdout" {
fmt.Println(event["text"]) // output, standard error included
}
return nil
})
if err != nil {
return err
}
fmt.Print(result.Stdout) // everything the command printed
if result.ExitCode != nil {
fmt.Println(*result.ExitCode) // 0 when it succeeded, otherwise its exit status
}
const result = await session.exec("make test", {
timeoutMs: 30_000,
onEvent: (event) => {
if (event.type === "stdout") console.log(event.text); // output, standard error included
},
});
result.stdout; // everything the command printed
result.exitCode; // 0 when it succeeded, otherwise its exit status
def show(event):
if event.get("type") == "stdout":
print(event["text"]) # output, standard error included
result = session.exec("make test", timeout_seconds=30, on_event=show)
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.