SECONDHAND docs
Wrap a command, pay for the seconds it ran, get a signed receipt, and withdraw whatever you did not use.
Quickstart
Needs Node 18 or newer. The npm package is not published yet, so install from the repo source:
# in a clone of the repo npm i -g . # local run, simulated settlement secondhand run -- echo hello
Locally the command runs on your machine. Seconds are metered and the receipt is signed for real, but no money moves (settlement: simulated). Use it to see how billing behaves before you fund anything.
$ secondhand run --budget 2.00 -- python scraper.py session 0x7f3a…c21e metered 412 s 0.1648 USDG receipt ~/.secondhand/receipts/0x7f3a….json settled 0.1648 USDG, refund 1.8352 USDG (simulated)
Your account is an ed25519 key created on first use in ~/.secondhand (override with SECONDHAND_HOME). There is no sign-up and no API key.
Console
The web console does everything the CLI does without installing anything. It generates an ed25519 key in your browser and keeps it in local storage.
- Open the console. A key is created for you; its account id is shown at the top.
- Connect a wallet, approve USDG and deposit. Credit lands after the confirmations listed on Fund.
- Open a sandbox (shell, python or node) with a budget. Type commands in the terminal while the per-second meter runs.
- Stop the session to get the receipt. Use the Withdraw panel to pull unused credit back.
Move keys between the browser and the CLI with secondhand key export and secondhand key import <file>. Clearing browser storage deletes the browser key, so export it first if it holds credit.
Run in the cloud
Add --cloud to send the command to a node. Each request is signed with your key.
# your account id and balance secondhand account --cloud https://api.secondhandhq.xyz secondhand run --cloud --worker python --budget 0.05 -- python -c "print(6*7)" # or set the node once export SECONDHAND_CLOUD=https://api.secondhandhq.xyz
- Opening a session holds the budget from your balance. Stopping pays for the seconds used and returns the rest.
- When the budget runs out the sandbox is destroyed and the receipt says budget_exhausted.
- Workers: shell, python, node.
- Each sandbox is a Docker container with --network none, a read-only root, all capabilities dropped and a non-root user. A node can run it under gVisor (runsc) for a user-space kernel.
- To chain commands, wrap them in one shell: secondhand run --cloud --worker shell -- sh -c 'cmd1; cmd2'.
Fund
Balances are paid in USDG on Robinhood Chain (chain id 4663, 6 decimals) through the compute vault. The node credits your account after a few confirmations.
In the browser
Run secondhand account to get your account id, then open /fund, connect a wallet and deposit. The CLI prints a link with the account filled in.
From a wallet or explorer
Approve the vault for the amount on the USDG token, then call deposit(bytes20 account, uint256 amount) on the vault. 1 USDG is 1000000. The account is your 20-byte account id.
| Item | Value |
|---|---|
| Chain | Robinhood Chain (4663) |
| Vault | shown on /fund once the node has deposits enabled |
| Token | USDG |
The values above are read live from GET /v1/node.
Withdraw
Unused credit is yours. The node signs an EIP-712 voucher, you submit it to the vault, and USDG goes to the address you chose.
secondhand withdraw 4.76 --to 0xYourAddress --cloud https://api.secondhandhq.xyz
This prints the voucher and ready calldata. Submit it from any wallet, or press Withdraw in the console.
- POST /v1/withdrawals debits your node balance and returns a voucher valid for one hour.
- Anyone can call vault.withdraw(account, to, amount, nonce, expiry, v, r, s). Money always goes to to.
- If the voucher is not used before expiry, the node sees the deadline pass on chain and re-credits the amount.
- One pending voucher per account at a time. Each nonce works once.
EIP-712 domain: {name: "ComputeVault", version: "1", chainId: 4663, verifyingContract: vault}. Type:
Withdrawal(bytes20 account, address to, uint256 amount, uint256 nonce, uint256 expiry)
Limits
On the public node:
Self-hosted nodes set their own values. Exceeding a limit returns 429, or 409 if a session or withdrawal is already pending.
Commands
| Command | What it does |
|---|---|
| secondhand run [--budget 2.00] -- <cmd> | Run locally, simulated settlement. |
| secondhand run --cloud [url] [--budget 0.24] [--worker shell|python|node] -- <cmd> | Run in a cloud sandbox and settle against your balance. |
| secondhand account [--cloud [url]] | Your account id, plus balance and recent sessions with a node. |
| secondhand quote <seconds> | What that many seconds cost. |
| secondhand receipts [--json] | Every receipt on this machine, newest first. |
| secondhand verify <file|session id> | Checks a receipt signature. An edit to any field breaks it. |
| secondhand whoami | Your key id and public key. |
| secondhand withdraw <amount> --to 0xADDR --cloud [url] | Prints a voucher and calldata. Submit it with any wallet or in the console. |
| secondhand key export / key import <file> | Move the key between the CLI and the browser. |
State lives in ~/.secondhand (SECONDHAND_HOME). SECONDHAND_CLOUD sets the default node.
Receipts
Every session ends in a JSON receipt saved under ~/.secondhand/receipts/ and, for cloud sessions, public at /r/<session id>.
{
"v": 1, "mode": "cloud", "session": "0x7f3a…c21e", "account": "0x9f2c…",
"worker": "python", "image": "…", "opened": 1764200000000, "closed": 1764200412000,
"seconds": 412, "rate": "0.0004", "budget": "2.00",
"paid": "0.164800", "refund": "1.835200",
"status": "completed", "settlement": "ledger",
"execs": [{ "cmd": "python scraper.py", "code": 0, "signal": null }],
"output": "sha256:91c7…",
"node": { "id": "0xb8f6…", "pub": "MCow…" },
"sig": "5d0a…"
}- mode is local or cloud. settlement is simulated or ledger.
- status is one of completed, budget_exhausted, idle_timeout, interrupted, node_shutdown, failed.
- output is the sha256 of everything written to stdout and stderr.
- sig is an ed25519 signature over the canonical JSON of every other field: keys sorted, no whitespace.
SDK
import secondhand from "secondhand";
const s = await secondhand.open({ cloud: "https://api.secondhandhq.xyz", budget: "0.5", worker: "python" });
const out = await s.exec("python main.py");
const receipt = await s.stop();
secondhand.quote(600); // cost of 600 seconds
secondhand.verifyReceipt(receipt);
secondhand.receipts();
secondhand.cloud(url).withdraw({ amount: "1.00", to: "0xYourAddress" });open takes budget or seconds. Leave out cloud to run locally.
MCP
Install from the repo source (npm i -g . in a clone), then add the server to Claude Desktop or Cursor:
{
"mcpServers": {
"secondhand": {
"command": "secondhand-mcp",
"args": [],
"env": { "SECONDHAND_CLOUD": "https://api.secondhandhq.xyz" }
}
}
}| Tool | Input |
|---|---|
| run | {cmd, budget?, worker?, cloud?} |
| quote | {seconds} |
| account | {} |
| receipts | {limit?} |
HTTP API
All requests are signed except GET /v1/node and GET /v1/receipts/:id. The CLI, SDK and console sign for you.
| Header | Value |
|---|---|
| x-acct-key | ed25519 public key, SPKI DER, base64 |
| x-acct-ts | time in milliseconds |
| x-acct-nonce | hex, 16 to 64 characters, single use |
| x-acct-sig | base64 ed25519 signature |
sig = ed25519_sign(METHOD + "\n" + PATH + "\n" + TS + "\n" + NONCE + "\n" + sha256hex(body))
The window is 60 seconds and nonces cannot be reused. The account id is 0x plus the first 40 hex characters of sha256(spki).
| Endpoint | Returns |
|---|---|
| GET /v1/node | Node id, rate, limits, deposit details. Public. |
| GET /v1/account | Balance, held funds, deposits, recent sessions. |
| POST /v1/sessions | Opens a sandbox. Body {worker, budget | seconds}. |
| POST /v1/sessions/:id/exec | Runs {cmd}. Streams NDJSON: {t:"stdout"|"stderr", d:base64} lines, then {t:"exit", code, signal, ms, closed?, truncated?}. |
| POST /v1/sessions/:id/stop | {receipt} |
| GET /v1/sessions/:id | Session state. |
| GET /v1/receipts/:id | A closed session's receipt. Public. |
| POST /v1/withdrawals | Body {amount, to}. Returns {withdrawal: {account, to, amount, nonce, expiry, v, r, s, vault, chainId, calldata, status}}. |
| GET /v1/withdrawals | Your vouchers and their status. |
Errors
| 401 | Bad signature. |
| 402 | Balance too low. |
| 409 | Busy, or a withdrawal is pending. |
| 429 | Limit reached or rate limited. |
